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.

data-access/src/EntitySource.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\DataAccess;
4
5
use Wikimedia\Assert\Assert;
6
7
/**
8
 * An EntitySource includes information needed to interact with one or more entity types at a given source.
9
 * EntitySource can only currently be used via direct database access.
10
 *
11
 * @see EntitySourceDefinitions for defining multiple EntitySources within a single site.
12
 *
13
 * @license GPL-2.0-or-later
14
 */
15
class EntitySource {
16
17
	/**
18
	 * @var string
19
	 */
20
	private $sourceName;
21
22
	/**
23
	 * @var string|false The name of the database to use (use false for the local db)
24
	 */
25
	private $databaseName;
26
27
	/**
28
	 * @var string[]
29
	 */
30
	private $entityTypes;
31
32
	/**
33
	 * @var int[]
34
	 */
35
	private $entityNamespaceIds;
36
37
	/**
38
	 * @var string[]
39
	 */
40
	private $entitySlots;
41
42
	/**
43
	 * @var string
44
	 */
45
	private $conceptBaseUri;
46
47
	private $rdfNodeNamespacePrefix;
48
49
	private $rdfPredicateNamespacePrefix;
50
51
	/**
52
	 * @var string
53
	 */
54
	private $interwikiPrefix;
55
56
	/**
57
	 * @param string $name Unique name for the source for a given configuration / site, used for indexing the sources internally.
58
	 *        This does not have to be a wikiname, sitename or dbname, it can for example just be 'properties'.
59
	 * @param string|false $databaseName The name of the database to use (use false for the local db)
60
	 * @param array $entityNamespaceIdsAndSlots Associative array indexed by entity type (string), values are
61
	 * array of form [ 'namespaceId' => int, 'slot' => string ]
62
	 * @param string $conceptBaseUri
63
	 * @param string $rdfNodeNamespacePrefix
64
	 * @param string $rdfPredicateNamespacePrefix
65
	 * @param string $interwikiPrefix
66
	 */
67
	public function __construct(
68
		$name,
69
		$databaseName,
70
		array $entityNamespaceIdsAndSlots,
71
		$conceptBaseUri,
72
		$rdfNodeNamespacePrefix,
73
		$rdfPredicateNamespacePrefix,
74
		$interwikiPrefix
75
	) {
76
		Assert::parameterType( 'string', $name, '$name' );
77
		Assert::parameter( is_string( $databaseName ) || $databaseName === false, '$databaseName', 'must be a string or false' );
78
		Assert::parameterType( 'string', $conceptBaseUri, '$conceptBaseUri' );
79
		Assert::parameterType( 'string', $rdfNodeNamespacePrefix, '$rdfNodeNamespacePrefix' );
80
		Assert::parameterType( 'string', $rdfPredicateNamespacePrefix, '$rdfPredicateNamespacePrefix' );
81
		Assert::parameterType( 'string', $interwikiPrefix, '$interwikiPrefix' );
82
		$this->assertEntityNamespaceIdsAndSlots( $entityNamespaceIdsAndSlots );
83
84
		$this->sourceName = $name;
85
		$this->databaseName = $databaseName;
86
		$this->conceptBaseUri = $conceptBaseUri;
87
		$this->rdfNodeNamespacePrefix = $rdfNodeNamespacePrefix;
88
		$this->rdfPredicateNamespacePrefix = $rdfPredicateNamespacePrefix;
89
		$this->interwikiPrefix = $interwikiPrefix;
90
91
		$this->setEntityTypeData( $entityNamespaceIdsAndSlots );
92
	}
93
94
	private function assertEntityNamespaceIdsAndSlots( array $entityNamespaceIdsAndSlots ) {
95
		foreach ( $entityNamespaceIdsAndSlots as $entityType => $namespaceIdAndSlot ) {
96
			if ( !is_string( $entityType ) ) {
97
				throw new \InvalidArgumentException( 'Entity type name not a string: ' . $entityType );
98
			}
99
			if ( !is_array( $namespaceIdAndSlot ) ) {
100
				throw new \InvalidArgumentException( 'Namespace and slot not defined for entity type: ' . $entityType );
101
			}
102
			if ( !array_key_exists( 'namespaceId', $namespaceIdAndSlot ) ) {
103
				throw new \InvalidArgumentException( 'Namespace ID not defined for entity type: ' . $entityType );
104
			}
105
			if ( !array_key_exists( 'slot', $namespaceIdAndSlot ) ) {
106
				throw new \InvalidArgumentException( 'Slot not defined for entity type: ' . $entityType );
107
			}
108
			if ( !is_int( $namespaceIdAndSlot['namespaceId'] ) ) {
109
				throw new \InvalidArgumentException( 'Namespace ID for entity type must be an integer: ' . $entityType );
110
			}
111
			if ( !is_string( $namespaceIdAndSlot['slot'] ) ) {
112
				throw new \InvalidArgumentException( 'Slot for entity type must be a string: ' . $entityType );
113
			}
114
		}
115
	}
116
117
	private function setEntityTypeData( array $entityNamespaceIdsAndSlots ) {
118
		$this->entityTypes = array_keys( $entityNamespaceIdsAndSlots );
0 ignored issues
show
Documentation Bug introduced by
It seems like array_keys($entityNamespaceIdsAndSlots) of type array<integer,integer|string> is incompatible with the declared type array<integer,string> of property $entityTypes.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
119
		$this->entityNamespaceIds = array_map(
120
			function ( $x ) {
121
				return $x['namespaceId'];
122
			},
123
			$entityNamespaceIdsAndSlots
124
		);
125
		$this->entitySlots = array_map(
126
			function ( $x ) {
127
				return $x['slot'];
128
			},
129
			$entityNamespaceIdsAndSlots
130
		);
131
	}
132
133
	/**
134
	 * @return string|false The name of the database to use (use false for the local db)
135
	 */
136
	public function getDatabaseName() {
137
		return $this->databaseName;
138
	}
139
140
	public function getSourceName() {
141
		return $this->sourceName;
142
	}
143
144
	public function getEntityTypes() {
145
		return $this->entityTypes;
146
	}
147
148
	public function getEntityNamespaceIds() {
149
		return $this->entityNamespaceIds;
150
	}
151
152
	public function getEntitySlotNames() {
153
		return $this->entitySlots;
154
	}
155
156
	public function getConceptBaseUri() {
157
		return $this->conceptBaseUri;
158
	}
159
160
	public function getRdfNodeNamespacePrefix() {
161
		return $this->rdfNodeNamespacePrefix;
162
	}
163
164
	public function getRdfPredicateNamespacePrefix() {
165
		return $this->rdfPredicateNamespacePrefix;
166
	}
167
168
	public function getInterwikiPrefix() {
169
		return $this->interwikiPrefix;
170
	}
171
172
}
173