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.

repo/includes/Hooks/InfoActionHookHandler.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
namespace Wikibase\Repo\Hooks;
4
5
use Html;
6
use IContextSource;
7
use PageProps;
8
use SiteLookup;
9
use Title;
10
use Wikibase\Lib\Store\EntityIdLookup;
11
use Wikibase\Lib\Store\EntityNamespaceLookup;
12
use Wikibase\Repo\Store\SubscriptionLookup;
13
14
/**
15
 * @license GPL-2.0-or-later
16
 * @author Amir Sarabadani <[email protected]>
17
 */
18
class InfoActionHookHandler {
19
20
	/**
21
	 * @var EntityNamespaceLookup
22
	 */
23
	private $namespaceChecker;
24
25
	/**
26
	 * @var SubscriptionLookup
27
	 */
28
	private $subscriptionLookup;
29
30
	/**
31
	 * @var SiteLookup
32
	 */
33
	private $siteLookup;
34
35
	/**
36
	 * @var EntityIdLookup
37
	 */
38
	private $entityIdLookup;
39
40
	/**
41
	 * @var IContextSource
42
	 */
43
	private $context;
44
45
	/**
46
	 * @var PageProps
47
	 */
48
	private $pageProps;
49
50
	public function __construct(
51
		EntityNamespaceLookup $namespaceChecker,
52
		SubscriptionLookup $subscriptionLookup,
53
		SiteLookup $siteLookup,
54
		EntityIdLookup $entityIdLookup,
55
		IContextSource $context,
56
		PageProps $pageProps
57
	) {
58
		$this->namespaceChecker = $namespaceChecker;
59
		$this->subscriptionLookup = $subscriptionLookup;
60
		$this->siteLookup = $siteLookup;
61
		$this->entityIdLookup = $entityIdLookup;
62
		$this->context = $context;
63
		$this->pageProps = $pageProps;
64
	}
65
66
	/**
67
	 * @param IContextSource $context
68
	 * @param array $pageInfo
69
	 *
70
	 * @return array[]
71
	 */
72
	public function handle( IContextSource $context, array $pageInfo ) {
73
		// Check if wikibase namespace is enabled
74
		$title = $context->getTitle();
75
76
		if ( $this->namespaceChecker->isNamespaceWithEntities( $title->getNamespace() )
77
			&& $title->exists()
78
		) {
79
			$pageInfo['header-properties'][] = $this->getSubscriptionsInfo( $title );
80
			$pageInfo['header-basic'] = array_merge( $pageInfo['header-basic'], $this->getStatementsInfo( $title ) );
81
		}
82
83
		return $pageInfo;
84
	}
85
86
	/**
87
	 * @param Title $title
88
	 *
89
	 * @return string[] HTML
90
	 */
91
	private function getSubscriptionsInfo( Title $title ) {
92
		$entity = $this->entityIdLookup->getEntityIdForTitle( $title );
93
94
		if ( $entity === null ) {
95
			return $this->getNoSubscriptionText();
96
		}
97
98
		$subscriptions = $this->subscriptionLookup->getSubscribers( $entity );
99
100
		if ( $subscriptions ) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $subscriptions of type string[] 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...
101
			return $this->formatSubscriptions( $subscriptions, $title );
102
		}
103
104
		return $this->getNoSubscriptionText();
105
	}
106
107
	/**
108
	 * @param Title $title
109
	 *
110
	 * @return string[] HTML
111
	 */
112
	private function getStatementsInfo( Title $title ) {
113
114
		$properties = $this->pageProps->getProperties( $title, [ 'wb-claims', 'wb-identifiers' ] );
115
116
		if ( $properties ) {
117
			return $this->formatProperties( $properties );
118
		}
119
120
		return [];
121
	}
122
123
	/**
124
	 * @param array $properties
125
	 *
126
	 * @return string[] HTML
127
	 */
128
	private function formatProperties( array $properties ) {
129
		$output = [];
130
131
		foreach ( $properties as $pageId => $pageProperties ) {
132
			foreach ( $pageProperties as $property => $value ) {
133
				$output[] = [
134
					$this->context->msg( 'wikibase-pageinfo-' . $property )->parse(),
135
					$this->context->getLanguage()->formatNum( (int)$value )
136
				];
137
			}
138
		}
139
140
		return $output;
141
	}
142
143
	/**
144
	 * @param string[] $subscriptions
145
	 * @param Title $title
146
	 *
147
	 * @return string[] HTML
148
	 */
149
	private function formatSubscriptions( array $subscriptions, Title $title ) {
150
		$output = '';
151
152
		foreach ( $subscriptions as $subscription ) {
153
			$link = $this->formatSubscription( $subscription, $title );
154
			$output .= Html::rawElement( 'li', [], $link );
155
156
		}
157
		$output = Html::rawElement( 'ul', [], $output );
158
		return [ $this->context->msg( 'wikibase-pageinfo-subscription' )->parse(), $output ];
159
	}
160
161
	/**
162
	 * @return string[] HTML
163
	 */
164
	private function getNoSubscriptionText() {
165
		return [
166
			$this->context->msg( 'wikibase-pageinfo-subscription' )->parse(),
167
			$this->context->msg( 'wikibase-pageinfo-subscription-none' )->parse()
168
		];
169
	}
170
171
	/**
172
	 * @param string $subscription
173
	 * @param Title $title
174
	 *
175
	 * @return string HTML
176
	 */
177
	private function formatSubscription( $subscription, Title $title ) {
178
		$site = $this->siteLookup->getSite( $subscription );
179
		if ( $site === null ) {
180
			return $subscription;
181
		}
182
183
		$url = $site->getPageUrl( 'Special:EntityUsage/' . $title->getText() );
184
		if ( $url === false ) {
185
			return $subscription;
186
		}
187
188
		return Html::element( 'a',
189
			[ 'href' => $url ],
190
			$subscription
191
		);
192
	}
193
194
}
195