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.

client/includes/Hooks/EditActionHookHandler.php (1 issue)

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
declare( strict_types = 1 );
4
5
namespace Wikibase\Client\Hooks;
6
7
use EditPage;
8
use Html;
9
use IContextSource;
10
use MediaWiki\Hook\EditPage__showStandardInputs_optionsHook;
11
use MessageLocalizer;
12
use OutputPage;
13
use Wikibase\Client\RepoLinker;
14
use Wikibase\Client\Usage\EntityUsage;
15
use Wikibase\Client\Usage\UsageLookup;
16
use Wikibase\Client\WikibaseClient;
17
use Wikibase\DataModel\Entity\EntityIdParser;
18
use Wikibase\Lib\Store\LanguageFallbackLabelDescriptionLookupFactory;
19
20
/**
21
 * Adds the Entity usage data in ActionEdit.
22
 *
23
 * @license GPL-2.0-or-later
24
 * @author Amir Sarabadani < [email protected] >
25
 */
26
class EditActionHookHandler implements EditPage__showStandardInputs_optionsHook {
27
28
	/**
29
	 * @var RepoLinker
30
	 */
31
	private $repoLinker;
32
33
	/**
34
	 * @var UsageLookup
35
	 */
36
	private $usageLookup;
37
38
	/**
39
	 * @var LanguageFallbackLabelDescriptionLookupFactory
40
	 */
41
	private $labelDescriptionLookupFactory;
42
43
	/**
44
	 * @var EntityIdParser
45
	 */
46
	private $idParser;
47
48
	public function __construct(
49
		RepoLinker $repoLinker,
50
		UsageLookup $usageLookup,
51
		LanguageFallbackLabelDescriptionLookupFactory $labelDescriptionLookupFactory,
52
		EntityIdParser $idParser
53
	) {
54
		$this->repoLinker = $repoLinker;
55
		$this->usageLookup = $usageLookup;
56
		$this->labelDescriptionLookupFactory = $labelDescriptionLookupFactory;
57
		$this->idParser = $idParser;
58
	}
59
60
	public static function factory(): self {
61
		$wikibaseClient = WikibaseClient::getDefaultInstance();
62
63
		$usageLookup = $wikibaseClient->getStore()->getUsageLookup();
64
		$labelDescriptionLookupFactory = new LanguageFallbackLabelDescriptionLookupFactory(
65
			$wikibaseClient->getLanguageFallbackChainFactory(),
66
			$wikibaseClient->getTermLookup(),
67
			$wikibaseClient->getTermBuffer()
68
		);
69
		$idParser = $wikibaseClient->getEntityIdParser();
70
71
		return new self(
72
			$wikibaseClient->newRepoLinker(),
73
			$usageLookup,
74
			$labelDescriptionLookupFactory,
75
			$idParser
76
		);
77
	}
78
79
	/**
80
	 * @param EditPage $editor
81
	 * @param OutputPage $out
82
	 * @param int $tabindex
83
	 */
84
	// phpcs:ignore MediaWiki.NamingConventions.LowerCamelFunctionsName.FunctionName
85
	public function onEditPage__showStandardInputs_options( $editor, $out, &$tabindex ): void {
86
		if ( $editor->section ) {
87
			// Shorten out, like template transclusion in core
88
			return;
89
		}
90
91
		// Check if there are usages to show
92
		$title = $editor->getTitle();
93
		$usages = $this->usageLookup->getUsagesForPage( $title->getArticleID() );
94
95
		if ( $usages ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $usages of type Wikibase\Client\Usage\EntityUsage[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
96
			$header = $this->getHeader( $out );
97
			$usageOutput = $this->formatEntityUsage( $usages, $out );
98
			$output = Html::rawElement(
99
				'div',
100
				[ 'class' => 'wikibase-entity-usage' ],
101
				$header . "\n" . $usageOutput
102
			);
103
			$editor->editFormTextAfterTools .= $output;
104
		}
105
106
		$out->addModules( 'wikibase.client.action.edit.collapsibleFooter' );
107
	}
108
109
	/**
110
	 * @param string[][] $rowAspects
111
	 * @param IContextSource $context
112
	 *
113
	 * @return string HTML
114
	 */
115
	private function formatAspects( array $rowAspects, IContextSource $context ): string {
116
		$aspects = [];
117
118
		foreach ( $rowAspects as $aspect ) {
119
			// Possible messages:
120
			//   wikibase-pageinfo-entity-usage-L
121
			//   wikibase-pageinfo-entity-usage-L-with-modifier
122
			//   wikibase-pageinfo-entity-usage-D
123
			//   wikibase-pageinfo-entity-usage-D-with-modifier
124
			//   wikibase-pageinfo-entity-usage-C
125
			//   wikibase-pageinfo-entity-usage-C-with-modifier
126
			//   wikibase-pageinfo-entity-usage-S
127
			//   wikibase-pageinfo-entity-usage-T
128
			//   wikibase-pageinfo-entity-usage-X
129
			//   wikibase-pageinfo-entity-usage-O
130
			$msgKey = 'wikibase-pageinfo-entity-usage-' . $aspect[0];
131
			if ( $aspect[1] !== null ) {
132
				$msgKey .= '-with-modifier';
133
			}
134
			$aspects[] = $context->msg( $msgKey, $aspect[1] )->parse();
135
		}
136
137
		return $context->getLanguage()->commaList( $aspects );
138
	}
139
140
	/**
141
	 * @param EntityUsage[] $usages
142
	 * @param IContextSource $context
143
	 * @return string HTML
144
	 */
145
	private function formatEntityUsage( array $usages, IContextSource $context ): string {
146
		$usageAspectsByEntity = [];
147
		$entityIds = [];
148
149
		foreach ( $usages as $entityUsage ) {
150
			$entityId = $entityUsage->getEntityId()->getSerialization();
151
			$entityIds[$entityId] = $entityUsage->getEntityId();
152
			$usageAspectsByEntity[$entityId][] = [
153
				$entityUsage->getAspect(),
154
				$entityUsage->getModifier()
155
			];
156
		}
157
158
		$output = '';
159
		$labelLookup = $this->labelDescriptionLookupFactory->newLabelDescriptionLookup(
160
			$context->getLanguage(),
161
			array_values( $entityIds )
162
		);
163
164
		foreach ( $usageAspectsByEntity as $entityId => $aspects ) {
165
			$label = $labelLookup->getLabel( $entityIds[$entityId] );
166
			$text = $label === null ? $entityId : $label->getText();
167
168
			$aspectContent = $this->formatAspects( $aspects, $context );
169
			$colon = $context->msg( 'colon-separator' )->plain();
170
			$output .= Html::rawElement(
171
				'li',
172
				[],
173
				$this->repoLinker->buildEntityLink(
174
					$entityIds[$entityId],
175
					[ 'external' ],
176
					$text
177
				) . $colon . $aspectContent
178
			);
179
		}
180
		return Html::rawElement( 'ul', [], $output );
181
	}
182
183
	/**
184
	 * @param MessageLocalizer $context
185
	 * @return string HTML
186
	 */
187
	private function getHeader( MessageLocalizer $context ): string {
188
		return Html::rawElement(
189
			'div',
190
			[ 'class' => 'wikibase-entityusage-explanation' ],
191
			$context->msg( 'wikibase-pageinfo-entity-usage' )->parseAsBlock()
192
		);
193
	}
194
195
}
196