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/Rdf/PropertyRdfBuilder.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 Wikibase\Repo\Rdf;
4
5
use Wikibase\DataModel\Entity\EntityDocument;
6
use Wikibase\DataModel\Entity\Property;
7
use Wikimedia\Purtle\RdfWriter;
8
9
/**
10
 * Factory to return Rdf builders for special parts of properties
11
 *
12
 * @license GPL-2.0-or-later
13
 * @author Amir Sarabadani <[email protected]>
14
 */
15
class PropertyRdfBuilder implements EntityRdfBuilder {
16
17
	const OBJECT_PROPERTY = 'ObjectProperty';
18
	const DATATYPE_PROPERTY = 'DatatypeProperty';
19
	const NO_NORMALIZATION = null;
20
21
	/**
22
	 * @var RdfVocabulary
23
	 */
24
	private $vocabulary;
25
26
	/**
27
	 * @var RdfWriter
28
	 */
29
	private $writer;
30
	/**
31
	 * @var array
32
	 */
33
	private $dataTypes;
34
35
	public function __construct( RdfVocabulary $vocabulary, RdfWriter $writer, array $dataTypes = [] ) {
36
		$this->vocabulary = $vocabulary;
37
		$this->writer = $writer;
38
		$this->dataTypes = $dataTypes;
39
	}
40
41
	/**
42
	 * Write predicates linking property entity to property predicates
43
	 * @param string $localName
44
	 * @param string $repositoryName
45
	 * @param string $propertyRdfType OWL data type (OBJECT_PROPERTY or DATATYPE_PROPERTY)
46
	 * @param string|null $normalizedPropertyRdfType Does the property have normalized predicates,
47
	 *  and if so does the property normalize to data or objects?
48
	 */
49
	private function writePropertyPredicates( $localName, $repositoryName, $propertyRdfType, $normalizedPropertyRdfType ) {
50
		$this->writer->say( RdfVocabulary::NS_ONTOLOGY, 'directClaim' )->is(
51
			$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_DIRECT_CLAIM],
52
			$localName
53
		);
54
		$this->writer->say( RdfVocabulary::NS_ONTOLOGY, 'claim' )->is(
55
			$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_CLAIM],
56
			$localName
57
		);
58
		$this->writer->say( RdfVocabulary::NS_ONTOLOGY, 'statementProperty' )->is(
59
			$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_CLAIM_STATEMENT],
60
			$localName
61
		);
62
		$this->writer->say( RdfVocabulary::NS_ONTOLOGY, 'statementValue' )->is(
63
			$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_CLAIM_VALUE],
64
			$localName
65
		);
66
		$this->writer->say( RdfVocabulary::NS_ONTOLOGY, 'qualifier' )->is(
67
			$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_QUALIFIER],
68
			$localName
69
		);
70
		$this->writer->say( RdfVocabulary::NS_ONTOLOGY, 'qualifierValue' )->is(
71
			$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_QUALIFIER_VALUE],
72
			$localName
73
		);
74
		$this->writer->say( RdfVocabulary::NS_ONTOLOGY, 'reference' )->is(
75
			$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_REFERENCE],
76
			$localName
77
		);
78
		$this->writer->say( RdfVocabulary::NS_ONTOLOGY, 'referenceValue' )->is(
79
			$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_REFERENCE_VALUE],
80
			$localName
81
		);
82
		$this->writer->say( RdfVocabulary::NS_ONTOLOGY, 'novalue' )->is(
83
			$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_NOVALUE],
84
			$localName
85
		);
86
87
		if ( $normalizedPropertyRdfType !== self::NO_NORMALIZATION ) {
88
			$this->writer->say( RdfVocabulary::NS_ONTOLOGY, 'directClaimNormalized' )->is(
89
				$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_DIRECT_CLAIM_NORM],
90
				$localName
91
			);
92
			$this->writer->say( RdfVocabulary::NS_ONTOLOGY, 'statementValueNormalized' )->is(
93
				$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_CLAIM_VALUE_NORM],
94
				$localName
95
			);
96
			$this->writer->say( RdfVocabulary::NS_ONTOLOGY, 'qualifierValueNormalized' )->is(
97
				$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_QUALIFIER_VALUE_NORM],
98
				$localName
99
			);
100
			$this->writer->say( RdfVocabulary::NS_ONTOLOGY, 'referenceValueNormalized' )->is(
101
				$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_REFERENCE_VALUE_NORM],
102
				$localName
103
			);
104
		}
105
106
		// Always object properties
107
		$this->writer->about(
108
			$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_CLAIM],
109
			$localName
110
		)->a( 'owl', 'ObjectProperty' );
111
		$this->writer->about(
112
			$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_CLAIM_VALUE],
113
			$localName
114
		)->a( 'owl', 'ObjectProperty' );
115
		$this->writer->about(
116
			$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_QUALIFIER_VALUE],
117
			$localName
118
		)->a( 'owl', 'ObjectProperty' );
119
		$this->writer->about(
120
			$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_REFERENCE_VALUE],
121
			$localName
122
		)->a( 'owl', 'ObjectProperty' );
123
124
		$this->writer->about(
125
			$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_DIRECT_CLAIM],
126
			$localName
127
		)->a( 'owl', $propertyRdfType );
128
		$this->writer->about(
129
			$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_CLAIM_STATEMENT],
130
			$localName
131
		)->a( 'owl', $propertyRdfType );
132
		$this->writer->about(
133
			$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_QUALIFIER],
134
			$localName
135
		)->a( 'owl', $propertyRdfType );
136
		$this->writer->about(
137
			$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_REFERENCE],
138
			$localName
139
		)->a( 'owl', $propertyRdfType );
140
141
		if ( $normalizedPropertyRdfType !== self::NO_NORMALIZATION ) {
142
			$this->writer->about(
143
				$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_CLAIM_VALUE_NORM],
144
				$localName
145
			)->a( 'owl', 'ObjectProperty' );
146
			$this->writer->about(
147
				$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_QUALIFIER_VALUE_NORM],
148
				$localName
149
			)->a( 'owl', 'ObjectProperty' );
150
			$this->writer->about(
151
				$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_REFERENCE_VALUE_NORM],
152
				$localName
153
			)->a( 'owl', 'ObjectProperty' );
154
155
			$this->writer->about(
156
				$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_DIRECT_CLAIM_NORM],
157
				$localName
158
			)->a( 'owl', $normalizedPropertyRdfType );
159
		}
160
	}
161
162
	/**
163
	 * Check if the property describes link between objects
164
	 * or just data item.
165
	 *
166
	 * @param Property $property
167
	 * @return string RDF/OWL type name for this property.
168
	 */
169
	private function getPropertyRdfType( Property $property ) {
170
		return $this->dataTypes[$property->getDataTypeId()] ?? self::DATATYPE_PROPERTY;
171
	}
172
173
	/**
174
	 * @param Property $property
175
	 *
176
	 * @return string|null
177
	 */
178
	private function getNormalizedPropertyRdfType( Property $property ) {
179
		switch ( $property->getDataTypeId() ) {
180
			case 'quantity':
181
				return self::DATATYPE_PROPERTY;
182
			case 'external-id':
183
				return self::OBJECT_PROPERTY;
184
			default:
185
				return self::NO_NORMALIZATION;
186
		}
187
	}
188
189
	/**
190
	 * Write definition for wdno:P123 class to use as novalue
191
	 * @param string $localName
192
	 * @param string $repositoryName
193
	 */
194
	private function writeNovalueClass( $localName, $repositoryName ) {
195
		$this->writer->about(
196
			$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_NOVALUE],
197
			$localName
198
		)->a( 'owl', 'Class' );
199
		$stableBNodeLabel = md5( implode( '-', [ 'owl:complementOf', $repositoryName, $localName ] ) );
200
		$internalClass = $this->writer->blank( $stableBNodeLabel );
201
		$this->writer->say( 'owl', 'complementOf' )->is( '_', $internalClass );
202
		$this->writer->about( '_', $internalClass )->say( 'a' )->is( 'owl', 'Restriction' );
203
		$this->writer->say( 'owl', 'onProperty' )->is(
204
			$this->vocabulary->propertyNamespaceNames[$repositoryName][RdfVocabulary::NSP_DIRECT_CLAIM],
205
			$localName
206
		);
207
		$this->writer->say( 'owl', 'someValuesFrom' )->is( 'owl', 'Thing' );
208
	}
209
210
	private function addProperty( Property $property ) {
211
		$id = $property->getId();
212
		$propertyLName = $this->vocabulary->getEntityLName( $id );
0 ignored issues
show
It seems like $id defined by $property->getId() on line 211 can be null; however, Wikibase\Repo\Rdf\RdfVocabulary::getEntityLName() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
213
		$repositoryName = $this->vocabulary->getEntityRepositoryName( $id );
0 ignored issues
show
It seems like $id defined by $property->getId() on line 211 can be null; however, Wikibase\Repo\Rdf\RdfVoc...tEntityRepositoryName() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
214
215
		$this->writer->about(
216
			$this->vocabulary->entityNamespaceNames[$repositoryName],
217
			$propertyLName
218
		)->a( RdfVocabulary::NS_ONTOLOGY, $this->vocabulary->getEntityTypeName( $property->getType() ) );
219
220
		$this->writer->say( RdfVocabulary::NS_ONTOLOGY, 'propertyType' )
221
			->is( $this->vocabulary->getDataTypeURI( $property ) );
222
223
		$this->writePropertyPredicates(
224
			$propertyLName,
225
			$repositoryName,
226
			$this->getPropertyRdfType( $property ),
227
			$this->getNormalizedPropertyRdfType( $property )
228
		);
229
		$this->writeNovalueClass( $propertyLName, $repositoryName );
230
	}
231
232
	/**
233
	 * Map a property to the RDF graph
234
	 *
235
	 * @param EntityDocument $entity
236
	 */
237
	public function addEntity( EntityDocument $entity ) {
238
		if ( !$entity instanceof Property ) {
239
			return;
240
		}
241
242
		$this->addProperty( $entity );
243
	}
244
245
	/**
246
	 * Map some aspects of a property to the RDF graph, as it should appear in the stub
247
	 * representation of the property.
248
	 *
249
	 * @param EntityDocument $entity
250
	 */
251
	public function addEntityStub( EntityDocument $entity ) {
252
		if ( !$entity instanceof Property ) {
253
			return;
254
		}
255
256
		$this->addProperty( $entity );
257
	}
258
259
}
260