Issues (65)

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/ItemDiffer.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 InvalidArgumentException;
7
use Wikibase\DataModel\Entity\EntityDocument;
8
use Wikibase\DataModel\Entity\Item;
9
use Wikibase\DataModel\Entity\ItemId;
10
use Wikibase\DataModel\SiteLinkList;
11
12
/**
13
 * @since 1.0
14
 *
15
 * @license GPL-2.0-or-later
16
 * @author Jeroen De Dauw < [email protected] >
17
 */
18
class ItemDiffer 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 6
		$this->recursiveMapDiffer = new MapDiffer( true );
32 6
		$this->statementListDiffer = new StatementListDiffer();
33 6
	}
34 6
35
	/**
36
	 * @param string $entityType
37
	 *
38
	 * @return bool
39
	 */
40
	public function canDiffEntityType( $entityType ) {
41
		return $entityType === 'item';
42
	}
43
44
	/**
45
	 * @param EntityDocument $from
46
	 * @param EntityDocument $to
47
	 *
48
	 * @return ItemDiff
49
	 * @throws InvalidArgumentException
50
	 */
51
	public function diffEntities( EntityDocument $from, EntityDocument $to ) {
52 4
		$this->assertIsItem( $from );
53 4
		$this->assertIsItem( $to );
54 4
55
		return $this->diffItems( $from, $to );
0 ignored issues
show
$from of type object<Wikibase\DataModel\Entity\EntityDocument> is not a sub-type of object<Wikibase\DataModel\Entity\Item>. 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\Item>. 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 4
	}
57
58
	private function assertIsItem( EntityDocument $item ) {
59 4
		if ( !( $item instanceof Item ) ) {
60 4
			throw new InvalidArgumentException( '$item must be an instance of Item' );
61
		}
62
	}
63 4
64
	public function diffItems( Item $from, Item $to ) {
65 6
		$diffOps = $this->recursiveMapDiffer->doDiff(
66 6
			$this->toDiffArray( $from ),
67 6
			$this->toDiffArray( $to )
68 6
		);
69 6
70
		$diffOps['claim'] = $this->statementListDiffer->getDiff( $from->getStatements(), $to->getStatements() );
71 6
72
		return new ItemDiff( $diffOps );
73 6
	}
74
75
	private function toDiffArray( Item $item ) {
76 6
		$array = [];
77 6
78
		$array['aliases'] = $item->getAliasGroups()->toTextArray();
79 6
		$array['label'] = $item->getLabels()->toTextArray();
80 6
		$array['description'] = $item->getDescriptions()->toTextArray();
81 6
		$array['links'] = $this->getSiteLinksInDiffFormat( $item->getSiteLinkList() );
82 6
83
		return $array;
84 6
	}
85
86
	private function getSiteLinksInDiffFormat( SiteLinkList $siteLinks ) {
87 6
		$linksInDiffFormat = [];
88 6
89
		foreach ( $siteLinks->toArray() as $siteLink ) {
90
			$linksInDiffFormat[$siteLink->getSiteId()] = [
91
				'name' => $siteLink->getPageName(),
92
				'badges' => array_map(
93 6
					function( ItemId $id ) {
94 1
						return $id->getSerialization();
95 1
					},
96 1
					$siteLink->getBadges()
97 1
				)
98
			];
99 1
		}
100 1
101 1
		return $linksInDiffFormat;
102 1
	}
103 6
104
	/**
105 6
	 * @param EntityDocument $entity
106
	 *
107
	 * @return ItemDiff
108
	 * @throws InvalidArgumentException
109
	 */
110
	public function getConstructionDiff( EntityDocument $entity ) {
111
		$this->assertIsItem( $entity );
112
		return $this->diffEntities( new Item(), $entity );
113
	}
114 2
115 2
	/**
116 2
	 * @param EntityDocument $entity
117
	 *
118
	 * @return ItemDiff
119
	 * @throws InvalidArgumentException
120
	 */
121
	public function getDestructionDiff( EntityDocument $entity ) {
122
		$this->assertIsItem( $entity );
123
		return $this->diffEntities( $entity, new Item() );
124
	}
125 1
126
}
127