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

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\Dumpers;
4
5
use InvalidArgumentException;
6
use MWContentSerializationException;
7
use MWException;
8
use Serializers\Serializer;
9
use Wikibase\DataModel\Entity\EntityId;
10
use Wikibase\DataModel\Services\Entity\EntityPrefetcher;
11
use Wikibase\DataModel\Services\Lookup\EntityLookupException;
12
use Wikibase\DataModel\Services\Lookup\PropertyDataTypeLookup;
13
use Wikibase\Lib\Serialization\CallbackFactory;
14
use Wikibase\Lib\Serialization\SerializationModifier;
15
use Wikibase\Lib\Store\EntityRevisionLookup;
16
use Wikibase\Lib\Store\RevisionedUnresolvedRedirectException;
17
use Wikibase\Lib\Store\StorageException;
18
19
/**
20
 * JsonDumpGenerator generates an JSON dump of a given set of entities, excluding
21
 * redirects.
22
 *
23
 * @license GPL-2.0-or-later
24
 * @author Daniel Kinzler
25
 */
26
class JsonDumpGenerator extends DumpGenerator {
27
28
	/**
29
	 * @var int flags to use with json_encode as a bit field, see PHP's JSON_XXX constants.
30
	 */
31
	private $jsonFlags = 0;
32
33
	/**
34
	 * @var Serializer
35
	 */
36
	private $entitySerializer;
37
38
	/**
39
	 * @var EntityRevisionLookup
40
	 */
41
	private $entityLookup;
42
43
	/**
44
	 * @var bool
45
	 */
46
	private $useSnippets = false;
47
48
	/**
49
	 * @var JsonDataTypeInjector
50
	 */
51
	private $dataTypeInjector;
52
53
	/**
54
	 * @param resource $out
55
	 * @param EntityRevisionLookup $lookup
56
	 * @param Serializer $entitySerializer
57
	 * @param EntityPrefetcher $entityPrefetcher
58
	 * @param PropertyDataTypeLookup $dataTypeLookup
59
	 *
60
	 * @throws InvalidArgumentException
61
	 */
62
	public function __construct(
63
		$out,
64
		EntityRevisionLookup $lookup,
65
		Serializer $entitySerializer,
66
		EntityPrefetcher $entityPrefetcher,
67
		PropertyDataTypeLookup $dataTypeLookup
68
	) {
69
		parent::__construct( $out, $entityPrefetcher );
70
71
		$this->entitySerializer = $entitySerializer;
72
		$this->entityLookup = $lookup;
73
74
		$this->dataTypeInjector = new JsonDataTypeInjector(
75
			new SerializationModifier(),
76
			new CallbackFactory(),
77
			$dataTypeLookup
78
		);
79
	}
80
81
	/**
82
	 * Do something before dumping data
83
	 */
84
	protected function preDump() {
85
		if ( !$this->useSnippets ) {
86
			$this->writeToDump( "[\n" );
87
		}
88
	}
89
90
	/**
91
	 * Do something after dumping data
92
	 */
93
	protected function postDump() {
94
		if ( !$this->useSnippets ) {
95
			$this->writeToDump( "\n]\n" );
96
		}
97
	}
98
99
	/**
100
	 * Do something before dumping entity
101
	 *
102
	 * @param int $dumpCount
103
	 */
104
	protected function preEntityDump( $dumpCount ) {
105
		if ( $dumpCount > 0 ) {
106
			$this->writeToDump( ",\n" );
107
		}
108
	}
109
110
	/**
111
	 * @param EntityId $entityId
112
	 *
113
	 * @throws EntityLookupException
114
	 * @throws StorageException
115
	 * @return string|null
116
	 */
117
	protected function generateDumpForEntityId( EntityId $entityId ) {
118
		try {
119
			$revision = $this->entityLookup->getEntityRevision( $entityId );
120
121
			if ( !$revision ) {
122
				throw new EntityLookupException( $entityId, 'Entity not found: ' . $entityId->getSerialization() );
123
			}
124
125
		} catch ( MWContentSerializationException $ex ) {
0 ignored issues
show
The class MWContentSerializationException does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
126
			throw new StorageException( 'Deserialization error for ' . $entityId->getSerialization() );
127
		} catch ( RevisionedUnresolvedRedirectException $e ) {
128
			// Redirects aren't supposed to be in the JSON dumps
129
			return null;
130
		}
131
132
		$entity = $revision->getEntity();
133
134
		$data = $this->entitySerializer->serialize( $entity );
135
136
		$data = $this->dataTypeInjector->injectEntitySerializationWithDataTypes( $data );
137
138
		// HACK: replace empty arrays with objects at the first level of the array
139
		foreach ( $data as &$element ) {
140
			if ( empty( $element ) ) {
141
				$element = (object)[];
142
			}
143
		}
144
145
		$data['lastrevid'] = $revision->getRevisionId();
146
147
		$json = $this->encode( $data );
148
149
		return $json;
150
	}
151
152
	/**
153
	 * Encodes the given data as JSON
154
	 *
155
	 * @param mixed $data
156
	 *
157
	 * @return string
158
	 * @throws MWException
159
	 */
160
	public function encode( $data ) {
161
		$json = json_encode( $data, $this->jsonFlags );
162
163
		if ( $json === false ) {
164
			throw new StorageException( 'Failed to encode data structure.' );
165
		}
166
167
		return $json;
168
	}
169
170
	/**
171
	 * @param bool $useSnippets Whether to output valid json (false) or only comma separated entities
172
	 */
173
	public function setUseSnippets( $useSnippets ) {
174
		$this->useSnippets = (bool)$useSnippets;
175
	}
176
177
	/**
178
	 * Flags to use with json_encode as a bit field, see PHP's JSON_XXX constants.
179
	 *
180
	 * @param int $jsonFlags
181
	 */
182
	public function setJsonFlags( $jsonFlags ) {
183
		$this->jsonFlags = $jsonFlags;
184
	}
185
186
	/**
187
	 * @return int
188
	 *
189
	 * @see setJsonFlags
190
	 */
191
	public function getJsonFlags() {
192
		return $this->jsonFlags;
193
	}
194
195
}
196