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/TermsRdfBuilder.php (4 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\Term\AliasesProvider;
7
use Wikibase\DataModel\Term\AliasGroup;
8
use Wikibase\DataModel\Term\AliasGroupList;
9
use Wikibase\DataModel\Term\DescriptionsProvider;
10
use Wikibase\DataModel\Term\LabelsProvider;
11
use Wikibase\DataModel\Term\TermList;
12
use Wikimedia\Purtle\RdfWriter;
13
14
/**
15
 * RDF mapping for entity terms.
16
 *
17
 * @license GPL-2.0-or-later
18
 */
19
class TermsRdfBuilder implements EntityRdfBuilder {
20
21
	/**
22
	 * @var RdfVocabulary
23
	 */
24
	private $vocabulary;
25
26
	/**
27
	 * @var RdfWriter
28
	 */
29
	private $writer;
30
31
	/**
32
	 * @var string[]|null a list of desired languages, or null for all languages.
33
	 */
34
	private $languages;
35
36
	/**
37
	 * @var string[][][] Map of type to array of [ ns, local ] for each label predicate
38
	 */
39
	private $labelPredicates;
40
41
	/**
42
	 * @param RdfVocabulary $vocabulary
43
	 * @param RdfWriter $writer
44
	 * @param string[][][] $labelPredicates Map of type to array of [ ns, local ] for each label predicate
45
	 * @param string[]|null $languages
46
	 */
47
	public function __construct(
48
		RdfVocabulary $vocabulary,
49
		RdfWriter $writer,
50
		array $labelPredicates = [],
51
		array $languages = null
52
	) {
53
		$this->vocabulary = $vocabulary;
54
		$this->writer = $writer;
55
		$this->languages = $languages === null ? null : array_flip( $languages );
56
		$this->labelPredicates = $labelPredicates;
57
	}
58
59
	/**
60
	 * Get predicates that will be used for labels.
61
	 * @param EntityDocument $entity
62
	 * @return string[][] array of [ ns, local ] for each label predicate
63
	 */
64
	private function getLabelPredicates( EntityDocument $entity ) {
65
		return $this->labelPredicates[$entity->getType()] ?? [
66
				[ 'rdfs', 'label' ],
67
				[ RdfVocabulary::NS_SKOS, 'prefLabel' ],
68
				[ RdfVocabulary::NS_SCHEMA_ORG, 'name' ],
69
			];
70
	}
71
72
	/**
73
	 * Adds the labels of the given entity to the RDF graph
74
	 *
75
	 * @param string $entityNamespace
76
	 * @param string $entityLName
77
	 * @param TermList $labels
78
	 * @param string[][] $labelPredicates array of [ ns, local ] for each label predicate
79
	 */
80
	private function addLabels( $entityNamespace, $entityLName, TermList $labels, array $labelPredicates ) {
81
		if ( empty( $labelPredicates ) ) {
82
			// If we want no predicates, no need to bother with the rest.
83
			return;
84
		}
85
		foreach ( $labels->toTextArray() as $languageCode => $labelText ) {
86
			if ( $this->languages !== null && !isset( $this->languages[$languageCode] ) ) {
87
				continue;
88
			}
89
90
			$this->writer->about( $entityNamespace, $entityLName );
91
			foreach ( $labelPredicates as $predicate ) {
92
				$this->writer->say( $predicate[0], $predicate[1] )->text( $labelText, $languageCode );
93
			}
94
		}
95
	}
96
97
	/**
98
	 * Adds the descriptions of the given entity to the RDF graph.
99
	 *
100
	 * @param string $entityNamespace
101
	 * @param string $entityLName
102
	 * @param TermList $descriptions
103
	 */
104
	private function addDescriptions( $entityNamespace, $entityLName, TermList $descriptions ) {
105
		foreach ( $descriptions->toTextArray() as $languageCode => $description ) {
106
			if ( $this->languages !== null && !isset( $this->languages[$languageCode] ) ) {
107
				continue;
108
			}
109
110
			$this->writer->about( $entityNamespace, $entityLName )
111
				->say( RdfVocabulary::NS_SCHEMA_ORG, 'description' )->text( $description, $languageCode );
112
		}
113
	}
114
115
	/**
116
	 * Adds the aliases of the given entity to the RDF graph.
117
	 *
118
	 * @param string $entityNamespace
119
	 * @param string $entityLName
120
	 * @param AliasGroupList $aliases
121
	 */
122
	private function addAliases( $entityNamespace, $entityLName, AliasGroupList $aliases ) {
123
		/** @var AliasGroup $aliasGroup */
124
		foreach ( $aliases as $aliasGroup ) {
125
			$languageCode = $aliasGroup->getLanguageCode();
126
			if ( $this->languages !== null && !isset( $this->languages[$languageCode] ) ) {
127
				continue;
128
			}
129
130
			foreach ( $aliasGroup->getAliases() as $alias ) {
131
				$this->writer->about(
132
					$entityNamespace,
133
					$entityLName
134
				)->say( RdfVocabulary::NS_SKOS, 'altLabel' )->text( $alias, $languageCode );
135
			}
136
		}
137
	}
138
139
	/**
140
	 * Add the entity's labels, descriptions, and aliases to the RDF graph.
141
	 *
142
	 * @see EntityRdfBuilder::addEntity
143
	 *
144
	 * @param EntityDocument $entity the entity to output.
145
	 * @suppress PhanTypeMismatchArgument
146
	 */
147
	public function addEntity( EntityDocument $entity ) {
148
		$entityId = $entity->getId();
149
		$entityLName = $this->vocabulary->getEntityLName( $entityId );
0 ignored issues
show
It seems like $entityId defined by $entity->getId() on line 148 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...
150
		$entityRepoName = $this->vocabulary->getEntityRepositoryName( $entityId );
0 ignored issues
show
It seems like $entityId defined by $entity->getId() on line 148 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...
151
		$entityNamespace = $this->vocabulary->entityNamespaceNames[$entityRepoName];
152
153
		if ( $entity instanceof LabelsProvider ) {
154
			$this->addLabels( $entityNamespace, $entityLName, $entity->getLabels(),
155
				$this->getLabelPredicates( $entity ) );
156
		}
157
158
		if ( $entity instanceof DescriptionsProvider ) {
159
			$this->addDescriptions( $entityNamespace, $entityLName, $entity->getDescriptions() );
160
		}
161
162
		if ( $entity instanceof AliasesProvider ) {
163
			$this->addAliases( $entityNamespace, $entityLName, $entity->getAliasGroups() );
164
		}
165
	}
166
167
	/**
168
	 * Add the entity's labels and descriptions to the RDF graph.
169
	 *
170
	 * @see EntityRdfBuilder::addEntityStub
171
	 *
172
	 * @param EntityDocument $entity the entity to output.
173
	 * @suppress PhanTypeMismatchArgument
174
	 */
175
	public function addEntityStub( EntityDocument $entity ) {
176
		$entityId = $entity->getId();
177
		$entityLName = $this->vocabulary->getEntityLName( $entityId );
0 ignored issues
show
It seems like $entityId defined by $entity->getId() on line 176 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...
178
		$entityRepoName = $this->vocabulary->getEntityRepositoryName( $entityId );
0 ignored issues
show
It seems like $entityId defined by $entity->getId() on line 176 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...
179
		$entityNamespace = $this->vocabulary->entityNamespaceNames[$entityRepoName];
180
181
		if ( $entity instanceof LabelsProvider ) {
182
			$this->addLabels( $entityNamespace, $entityLName, $entity->getLabels(),
183
				$this->getLabelPredicates( $entity ) );
184
		}
185
186
		if ( $entity instanceof DescriptionsProvider ) {
187
			$this->addDescriptions( $entityNamespace, $entityLName, $entity->getDescriptions() );
188
		}
189
	}
190
191
}
192