Issues (52)

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.

src/Diff/PropertyDiffer.php (2 issues)

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\DataModel\Services\Diff;
4
5
use Diff\Differ\MapDiffer;
6
use Diff\DiffOp\DiffOp;
7
use InvalidArgumentException;
8
use Wikibase\DataModel\Entity\EntityDocument;
9
use Wikibase\DataModel\Entity\Property;
10
use Wikibase\DataModel\Statement\StatementList;
11
12
/**
13
 * @since 1.0
14
 *
15
 * @license GPL-2.0-or-later
16
 * @author Jeroen De Dauw < [email protected] >
17
 */
18
class PropertyDiffer implements EntityDifferStrategy {
19
20
	/**
21
	 * @var MapDiffer
22
	 */
23
	private $recursiveMapDiffer;
24
25
	/**
26
	 * @var StatementListDiffer
27
	 */
28
	private $statementListDiffer;
29
30
	public function __construct() {
31 3
		$this->recursiveMapDiffer = new MapDiffer( true );
32 3
		$this->statementListDiffer = new StatementListDiffer();
33 3
	}
34 3
35
	/**
36
	 * @param string $entityType
37
	 *
38
	 * @return bool
39
	 */
40
	public function canDiffEntityType( $entityType ) {
41
		return $entityType === 'property';
42
	}
43
44
	/**
45
	 * @param EntityDocument $from
46
	 * @param EntityDocument $to
47
	 *
48
	 * @return EntityDiff
49
	 * @throws InvalidArgumentException
50
	 */
51
	public function diffEntities( EntityDocument $from, EntityDocument $to ) {
52
		$this->assertIsProperty( $from );
53
		$this->assertIsProperty( $to );
54
55
		return $this->diffProperties( $from, $to );
0 ignored issues
show
$from of type object<Wikibase\DataModel\Entity\EntityDocument> is not a sub-type of object<Wikibase\DataModel\Entity\Property>. It seems like you assume a concrete implementation of the interface Wikibase\DataModel\Entity\EntityDocument to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
$to of type object<Wikibase\DataModel\Entity\EntityDocument> is not a sub-type of object<Wikibase\DataModel\Entity\Property>. It seems like you assume a concrete implementation of the interface Wikibase\DataModel\Entity\EntityDocument to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
56
	}
57
58
	private function assertIsProperty( EntityDocument $property ) {
59 2
		if ( !( $property instanceof Property ) ) {
60 2
			throw new InvalidArgumentException( '$property must be an instance of Property' );
61
		}
62
	}
63 2
64
	public function diffProperties( Property $from, Property $to ) {
65 1
		$diffOps = $this->diffPropertyArrays(
66 1
			$this->toDiffArray( $from ),
67 1
			$this->toDiffArray( $to )
68 1
		);
69 1
70
		$diffOps['claim'] = $this->statementListDiffer->getDiff( $from->getStatements(), $to->getStatements() );
71 1
72
		return new EntityDiff( $diffOps );
73 1
	}
74
75
	/**
76
	 * @param array[] $from
77
	 * @param array[] $to
78
	 *
79
	 * @return DiffOp[]
80
	 */
81
	private function diffPropertyArrays( array $from, array $to ) {
82 3
		return $this->recursiveMapDiffer->doDiff( $from, $to );
83 3
	}
84
85
	/**
86
	 * @param Property $property
87
	 *
88
	 * @return array[]
89
	 */
90
	private function toDiffArray( Property $property ) {
91 3
		$array = [];
92 3
93
		$array['aliases'] = $property->getAliasGroups()->toTextArray();
94 3
		$array['label'] = $property->getLabels()->toTextArray();
95 3
		$array['description'] = $property->getDescriptions()->toTextArray();
96 3
97
		return $array;
98 3
	}
99
100
	/**
101
	 * @param EntityDocument $entity
102
	 *
103
	 * @return EntityDiff
104
	 * @throws InvalidArgumentException
105
	 */
106
	public function getConstructionDiff( EntityDocument $entity ) {
107 1
		$this->assertIsProperty( $entity );
108 1
109
		/** @var Property $entity */
110
		$diffOps = $this->diffPropertyArrays( [], $this->toDiffArray( $entity ) );
111 1
		$diffOps['claim'] = $this->statementListDiffer->getDiff( new StatementList(), $entity->getStatements() );
112 1
113
		return new EntityDiff( $diffOps );
114 1
	}
115
116
	/**
117
	 * @param EntityDocument $entity
118
	 *
119
	 * @return EntityDiff
120
	 * @throws InvalidArgumentException
121
	 */
122
	public function getDestructionDiff( EntityDocument $entity ) {
123 1
		$this->assertIsProperty( $entity );
124 1
125
		/** @var Property $entity */
126
		$diffOps = $this->diffPropertyArrays( $this->toDiffArray( $entity ), [] );
127 1
		$diffOps['claim'] = $this->statementListDiffer->getDiff( $entity->getStatements(), new StatementList() );
128 1
129
		return new EntityDiff( $diffOps );
130 1
	}
131
132
}
133