Issues (1401)

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.

view/src/StatementHtmlGenerator.php (2 issues)

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 Wikibase\View;
4
5
use ValueFormatters\NumberLocalizer;
6
use Wikibase\DataModel\Reference;
7
use Wikibase\DataModel\ReferenceList;
8
use Wikibase\DataModel\Services\ByPropertyIdGrouper;
9
use Wikibase\DataModel\Snak\Snak;
10
use Wikibase\DataModel\Snak\SnakList;
11
use Wikibase\DataModel\Statement\Statement;
12
use Wikibase\View\Template\TemplateFactory;
13
14
/**
15
 * Backend renderer that generates the HTML representation of a statement for use in an entity view.
16
 *
17
 * @license GPL-2.0-or-later
18
 */
19
class StatementHtmlGenerator {
20
21
	private static $rankNames = [
22
		Statement::RANK_DEPRECATED => 'deprecated',
23
		Statement::RANK_NORMAL => 'normal',
24
		Statement::RANK_PREFERRED => 'preferred'
25
	];
26
27
	/**
28
	 * @var TemplateFactory
29
	 */
30
	private $templateFactory;
31
32
	/**
33
	 * @var SnakHtmlGenerator
34
	 */
35
	private $snakHtmlGenerator;
36
37
	/**
38
	 * @var NumberLocalizer
39
	 */
40
	private $numberLocalizer;
41
42
	/**
43
	 * @var string[]
44
	 */
45
	private $referenceHeadings = [];
46
47
	/**
48
	 * @var string[]
49
	 */
50
	private $statementRankSelector = [];
51
52
	/**
53
	 * @var LocalizedTextProvider
54
	 */
55
	private $textProvider;
56
57
	public function __construct(
58
		TemplateFactory $templateFactory,
59
		SnakHtmlGenerator $snakHtmlGenerator,
60
		NumberLocalizer $numberLocalizer,
61
		LocalizedTextProvider $textProvider
62
	) {
63
		$this->snakHtmlGenerator = $snakHtmlGenerator;
64
		$this->templateFactory = $templateFactory;
65
		$this->numberLocalizer = $numberLocalizer;
66
		$this->textProvider = $textProvider;
67
	}
68
69
	/**
70
	 * Builds and returns the HTML representing a single WikibaseEntity's statement.
71
	 *
72
	 * @param Statement $statement
73
	 * @param string $editSectionHtml has the html for the edit section
74
	 *
75
	 * @return string HTML
76
	 */
77
	public function getHtmlForStatement( Statement $statement, $editSectionHtml ) {
78
		$mainSnakHtml = $this->snakHtmlGenerator->getSnakHtml(
79
			$statement->getMainSnak(),
80
			false
81
		);
82
83
		$rankHtml = $this->getRankSelector( $statement->getRank() );
84
85
		$referencesHeadingHtml = $this->getReferencesHeading( $statement );
86
87
		$references = $statement->getReferences();
88
		$referencesHtml = $this->getHtmlForReferences( $references );
89
90
		return $this->templateFactory->render(
91
			'wikibase-statementview',
92
			$statement->getGuid(),
93
			self::$rankNames[ $statement->getRank() ],
94
			$rankHtml,
95
			$mainSnakHtml,
96
			$this->getHtmlForQualifiers( $statement->getQualifiers() ),
97
			$editSectionHtml,
98
			$referencesHeadingHtml,
99
			$referencesHtml,
100
			$references->isEmpty() ? '' : 'wikibase-initially-collapsed'
101
		);
102
	}
103
104
	/**
105
	 * @param SnakList $qualifiers
106
	 *
107
	 * @return string HTML
108
	 * @suppress PhanTypeMismatchArgument
109
	 */
110
	private function getHtmlForQualifiers( SnakList $qualifiers ) {
111
		$qualifiersByProperty = new ByPropertyIdGrouper( $qualifiers );
112
113
		$snaklistviewsHtml = '';
114
115
		foreach ( $qualifiersByProperty->getPropertyIds() as $propertyId ) {
116
			$snaklistviewsHtml .= $this->getSnaklistviewHtml(
117
				$qualifiersByProperty->getByPropertyId( $propertyId )
0 ignored issues
show
$qualifiersByProperty->g...PropertyId($propertyId) is of type array<integer,object<Wik...el\PropertyIdProvider>>, but the function expects a array<integer,object<Wik...e\DataModel\Snak\Snak>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
118
			);
119
		}
120
121
		return $this->wrapInListview( $snaklistviewsHtml );
122
	}
123
124
	/**
125
	 * @param ReferenceList $referenceList
126
	 *
127
	 * @return string HTML
128
	 */
129
	private function getHtmlForReferences( ReferenceList $referenceList ) {
130
		$referencesHtml = '';
131
132
		foreach ( $referenceList as $reference ) {
133
			$referencesHtml .= $this->getHtmlForReference( $reference );
134
		}
135
136
		return $this->wrapInListview( $referencesHtml );
137
	}
138
139
	private function wrapInListview( $listviewContent ) {
140
		if ( $listviewContent !== '' ) {
141
			return $this->templateFactory->render( 'wikibase-listview', $listviewContent );
142
		} else {
143
			return '';
144
		}
145
	}
146
147
	/**
148
	 * @param Reference $reference
149
	 *
150
	 * @return string HTML
151
	 * @suppress PhanTypeMismatchArgument
152
	 */
153
	private function getHtmlForReference( Reference $reference ) {
154
		$snaks = $reference->getSnaks();
155
156
		$referenceSnaksByProperty = new ByPropertyIdGrouper( $snaks );
157
158
		$snaklistviewsHtml = '';
159
160
		foreach ( $referenceSnaksByProperty->getPropertyIds() as $propertyId ) {
161
			$snaklistviewsHtml .= $this->getSnaklistviewHtml(
162
				$referenceSnaksByProperty->getByPropertyId( $propertyId )
0 ignored issues
show
$referenceSnaksByPropert...PropertyId($propertyId) is of type array<integer,object<Wik...el\PropertyIdProvider>>, but the function expects a array<integer,object<Wik...e\DataModel\Snak\Snak>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
163
			);
164
		}
165
166
		return $this->templateFactory->render(
167
			'wikibase-referenceview',
168
			'wikibase-referenceview-' . $reference->getHash(),
169
			$snaklistviewsHtml
170
		);
171
	}
172
173
	/**
174
	 * @param Snak[] $snaks
175
	 *
176
	 * @return string HTML
177
	 */
178
	private function getSnaklistviewHtml( array $snaks ) {
179
		$snaksHtml = '';
180
		$i = 0;
181
182
		foreach ( $snaks as $snak ) {
183
			$snaksHtml .= $this->snakHtmlGenerator->getSnakHtml( $snak, ( $i++ === 0 ) );
184
		}
185
186
		return $this->templateFactory->render( 'wikibase-snaklistview', $snaksHtml );
187
	}
188
189
	/**
190
	 * @param Statement $statement
191
	 *
192
	 * @return string HTML
193
	 */
194
	private function getReferencesHeading( Statement $statement ) {
195
		$referenceCount = count( $statement->getReferences() );
196
197
		if ( !array_key_exists( $referenceCount, $this->referenceHeadings ) ) {
198
			$this->referenceHeadings[ $referenceCount ] = htmlspecialchars( $this->textProvider->get(
199
				'wikibase-statementview-references-counter',
200
				[
201
					$this->numberLocalizer->localizeNumber( $referenceCount ),
202
				]
203
			) );
204
		}
205
206
		return $this->referenceHeadings[ $referenceCount ];
207
	}
208
209
	/**
210
	 * @param int $rank
211
	 *
212
	 * @return string HTML
213
	 */
214
	private function getRankSelector( $rank ) {
215
		if ( !array_key_exists( $rank, $this->statementRankSelector ) ) {
216
			$rankName = self::$rankNames[ $rank ];
217
218
			// Messages: wikibase-statementview-rank-preferred, wikibase-statementview-rank-normal,
219
			// wikibase-statementview-rank-deprecated
220
			$rankSelector = $this->templateFactory->render(
221
				'wikibase-rankselector',
222
				'ui-state-disabled',
223
				'wikibase-rankselector-' . $rankName,
224
				htmlspecialchars( $this->textProvider->get( 'wikibase-statementview-rank-' . $rankName ) )
225
			);
226
227
			$this->statementRankSelector[ $rank ] = $rankSelector;
228
		}
229
		return $this->statementRankSelector[ $rank ];
230
	}
231
232
}
233