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/TruthyStatementRdfBuilder.php (1 issue)

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 InvalidArgumentException;
6
use Wikibase\DataModel\Entity\EntityDocument;
7
use Wikibase\DataModel\Entity\EntityId;
8
use Wikibase\DataModel\Statement\Statement;
9
use Wikibase\DataModel\Statement\StatementList;
10
use Wikibase\DataModel\Statement\StatementListProvider;
11
use Wikimedia\Purtle\RdfWriter;
12
13
/**
14
 * "Truthy" RDF mapping for wikibase statements, directly mapping properties to "best" values
15
 * without modelling statements as identifiable objects. "Best" statements per property are
16
 * statements that have the best non-deprecated rank.
17
 *
18
 * This simple property to value mapping excludes deprecated and non-"best" statements, ranks,
19
 * qualifiers, and references. This allows for a much simpler, much easier to query RDF structure
20
 * that allows searching for values similar to what would have been shown in infoboxes via Lua.
21
 *
22
 * If more information is needed, use FullStatementRdfBuilder instead.
23
 *
24
 * @see FullStatementRdfBuilder
25
 *
26
 * @license GPL-2.0-or-later
27
 * @author Daniel Kinzler
28
 * @author Stas Malyshev
29
 */
30
class TruthyStatementRdfBuilder implements EntityRdfBuilder {
31
32
	/**
33
	 * @var RdfVocabulary
34
	 */
35
	private $vocabulary;
36
37
	/**
38
	 * @var RdfWriter
39
	 */
40
	private $writer;
41
42
	/**
43
	 * @var SnakRdfBuilder
44
	 */
45
	private $snakBuilder;
46
47
	public function __construct( RdfVocabulary $vocabulary, RdfWriter $writer, SnakRdfBuilder $snakBuilder ) {
48
		$this->vocabulary = $vocabulary;
49
		$this->writer = $writer;
50
		$this->snakBuilder = $snakBuilder;
51
	}
52
53
	/**
54
	 * Adds Statements to the RDF graph.
55
	 *
56
	 * @param EntityId $entityId
57
	 * @param StatementList $statementList
58
	 */
59
	public function addStatements( EntityId $entityId, StatementList $statementList ) {
60
		// FIXME: getBestStatementPerProperty() uis expensive, share the result with FullStatementRdfBuilder!
61
		foreach ( $statementList->getPropertyIds() as $propertyId ) {
62
			foreach ( $statementList->getByPropertyId( $propertyId )->getBestStatements() as $statement ) {
63
				$this->addMainSnak( $entityId, $statement );
64
			}
65
		}
66
	}
67
68
	/**
69
	 * Adds the given Statement's main Snak to the RDF graph.
70
	 *
71
	 * @todo share more of this code with FullStatementRdfBuilder
72
	 *
73
	 * @param EntityId $entityId
74
	 * @param Statement $statement
75
	 *
76
	 * @throws InvalidArgumentException
77
	 */
78
	private function addMainSnak( EntityId $entityId, Statement $statement ) {
79
		$snak = $statement->getMainSnak();
80
81
		$entityLName = $this->vocabulary->getEntityLName( $entityId );
82
		$entityRepoName = $this->vocabulary->getEntityRepositoryName( $entityId );
83
84
		$snakNamespace = $this->vocabulary->statementNamespaceNames[$entityRepoName][RdfVocabulary::NS_VALUE];
85
86
		$this->writer->about( $this->vocabulary->entityNamespaceNames[$entityRepoName], $entityLName );
87
88
		$propertyRepoName = $this->vocabulary->getEntityRepositoryName( $snak->getPropertyId() );
89
		$this->snakBuilder->addSnak(
90
			$this->writer,
91
			$snakNamespace,
92
			$snak,
93
			$this->vocabulary->propertyNamespaceNames[$propertyRepoName][RdfVocabulary::NSP_DIRECT_CLAIM],
94
			$this->vocabulary->getStatementLName( $statement )
95
		);
96
	}
97
98
	/**
99
	 * Add truthy statements for the given entity to the RDF graph.
100
	 *
101
	 * @param EntityDocument $entity the entity to output.
102
	 */
103
	public function addEntity( EntityDocument $entity ) {
104
		$entityId = $entity->getId();
105
106
		if ( $entity instanceof StatementListProvider ) {
107
			$this->addStatements( $entityId, $entity->getStatements() );
0 ignored issues
show
It seems like $entityId defined by $entity->getId() on line 104 can be null; however, Wikibase\Repo\Rdf\Truthy...uilder::addStatements() 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...
108
		}
109
	}
110
111
	/**
112
	 * Does nothing, since Statements should not be part of entity stubs.
113
	 *
114
	 * @see EntityRdfBuilder::addEntityStub
115
	 *
116
	 * @param EntityDocument $entity the entity to output.
117
	 */
118
	public function addEntityStub( EntityDocument $entity ) {
119
		// noop
120
	}
121
122
}
123