Issues (5)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/ImageCaption.php (2 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace SMW\ImageCaption;
4
5
use SMW\Store;
6
use SMW\DIWikiPage;
7
use SMW\DIProperty;
8
use SMW\DataValues\MonolingualTextValue;
9
use SMW\DataValueFactory;
10
use SMWDIBlob as DIBlob;
11
use SMW\Utils\Normalizer;
12
use SMW\RequestOptions;
13
use Title;
14
use File;
15
use Html;
16
17
/**
18
 * @license GNU GPL v2+
19
 * @since 1.0
20
 *
21
 * @author mwjames
22
 */
23
class ImageCaption {
24
25
	const SCHEMA_TYPE = 'IMAGECAPTION_RULE_SCHEMA';
26
27
	/**
28
	 * @var Store
29
	 */
30
	private $store;
31
32
	/**
33
	 * @var RuleFinder
34
	 */
35
	private $ruleFinder;
36
37
	/**
38
	 * @var Rule
39
	 */
40
	private $rule;
41
42
	/**
43
	 * @since 1.0
44
	 *
45
	 * @param Store $store
46
	 * @param RuleFinder $ruleFinder
47
	 */
48
	public function __construct( Store $store, RuleFinder $ruleFinder ) {
49
		$this->store = $store;
50
		$this->ruleFinder = $ruleFinder;
51
	}
52
53
	/**
54
	 * @since 1.0
55
	 *
56
	 * @param Title $target
57
	 * @param File|false $file
58
	 * @param string &$caption
59
	 * @param string $languageCode
60
	 */
61
	public function modifyCaption( Title $target, $file, string &$caption, string $languageCode ) {
62
63
		if ( !$file instanceof File ) {
0 ignored issues
show
The class File does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
64
			return;
65
		}
66
67
		// Track count of embedded images
68
		if ( isset( $target->semanticimagecaptioncount ) ) {
69
			$target->semanticimagecaptioncount++;
70
		} else {
71
			$target->semanticimagecaptioncount = 1;
72
		}
73
74
		$subject = DIWikiPage::newFromTitle(
75
			$file->getTitle()
76
		);
77
78
		$text = $this->findText( $subject, $target, $caption, $languageCode );
79
80
		if ( $text !== '' ) {
81
			$caption = $text;
82
		}
83
	}
84
85
	private function findText( DIWikiPage $subject, Title $target, string $caption, string $languageCode ) : string {
86
87
		$requestOptions = new RequestOptions();
88
		$requestOptions->setCaller( __METHOD__ );
89
90
		$dataItems = $this->store->getPropertyValues(
91
			$subject,
92
			new DIProperty( '_INST' ),
93
			$requestOptions
94
		);
95
96
		$categories = [];
97
98
		foreach ( $dataItems as $dataItem ) {
99
			$categories[] = $dataItem->getDBKey();
100
		}
101
102
		$this->rule = $this->ruleFinder->findRule( $categories );
103
104
		if ( $this->rule->isEmpty() ) {
105
			return '';
106
		}
107
108
		if ( $caption !== '' && !$this->get( 'allow_caption_override', false ) ) {
109
			return '';
110
		}
111
112
		if ( ( $property = $this->get( 'caption_property', '' ) ) === '' ) {
113
			return '';
114
		}
115
116
		$property = DIProperty::newFromUserLabel( $property );
117
118
		$text = '';
119
		$maxLength = $this->get( 'max_length', 200 );
120
121
		if ( $property->findPropertyValueType() === MonolingualTextValue::TYPE_ID ) {
122
			$text .= $this->fetchTextByLanguageCode( $subject, $property, $languageCode );
123
		} else {
124
			$dataItems = $this->store->getPropertyValues(
125
				$subject,
126
				$property,
127
				$requestOptions
128
			);
129
130
			if ( $dataItems === [] ) {
131
				return '';
132
			}
133
134
			foreach ( $dataItems as $dataItem ) {
135
136
				if ( !$dataItem instanceof DIBlob ) {
137
					continue;
138
				}
139
140
				$text .= $dataItem->getString();
141
			}
142
		}
143
144
		$length = mb_strlen( $text );
145
146
		// Reduces the length and finish it with a whole word
147
		if ( $maxLength > 0 && $length >= $maxLength ) {
148
			$text = Normalizer::reduceLengthTo( $text, $maxLength ) . ' …';
149
		}
150
151
		if ( $this->get( 'add_figures_reference', false ) ) {
152
			$text = wfMessage( 'semantic-imagecaption-figures', $target->semanticimagecaptioncount )->parse() . "&nbsp;$text";
153
		}
154
155
		return $text;
156
	}
157
158
	private function fetchTextByLanguageCode( $subject, $property, $languageCode ) {
159
160
		try {
161
			$monolingualTextLookup = $this->store->service( 'MonolingualTextLookup' );
162
		} catch( ServiceNotFoundException $e ) {
0 ignored issues
show
The class SMW\ImageCaption\ServiceNotFoundException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
163
			return '';
164
		}
165
166
		if ( $monolingualTextLookup === null ) {
167
			return '';
168
		}
169
170
		$monolingualTextLookup->setCaller( __METHOD__ );
171
172
		$dataValue = $monolingualTextLookup->newDataValue(
173
			$subject,
174
			$property,
175
			$languageCode
176
		);
177
178
		if ( $dataValue === null ) {
179
			return '';
180
		}
181
182
		$dv = $dataValue->getTextValueByLanguageCode(
183
			$languageCode
184
		);
185
186
		return $dv->getShortWikiText();
187
	}
188
189
	private function get( $key, $default ) {
190
191
		if ( $this->rule->has( "then.$key" ) ) {
192
			return $this->rule->then( $key, $default );
193
		}
194
195
		if ( $this->rule->has( "$key" ) ) {
196
			return $this->rule->get( $key, $default );
197
		}
198
199
		return $default;
200
	}
201
202
}
203