Issues (67)

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/SerializerFactory.php (3 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;
4
5
use InvalidArgumentException;
6
use Serializers\DispatchableSerializer;
7
use Serializers\DispatchingSerializer;
8
use Serializers\Serializer;
9
use Wikibase\DataModel\Serializers\AliasGroupListSerializer;
10
use Wikibase\DataModel\Serializers\AliasGroupSerializer;
11
use Wikibase\DataModel\Serializers\ItemSerializer;
12
use Wikibase\DataModel\Serializers\PropertySerializer;
13
use Wikibase\DataModel\Serializers\ReferenceListSerializer;
14
use Wikibase\DataModel\Serializers\ReferenceSerializer;
15
use Wikibase\DataModel\Serializers\SiteLinkSerializer;
16
use Wikibase\DataModel\Serializers\SnakListSerializer;
17
use Wikibase\DataModel\Serializers\SnakSerializer;
18
use Wikibase\DataModel\Serializers\StatementListSerializer;
19
use Wikibase\DataModel\Serializers\StatementSerializer;
20
use Wikibase\DataModel\Serializers\TermListSerializer;
21
use Wikibase\DataModel\Serializers\TermSerializer;
22
use Wikibase\DataModel\Serializers\TypedSnakSerializer;
23
24
/**
25
 * Factory for constructing Serializer objects that can serialize WikibaseDataModel objects.
26
 *
27
 * @since 0.1
28
 *
29
 * @license GPL-2.0-or-later
30
 * @author Thomas Pellissier Tanon
31
 * @author Bene* < [email protected] >
32
 * @author Addshore
33
 */
34
class SerializerFactory {
35
36
	public const OPTION_DEFAULT = 0;
37
	/** @since 1.2.0 */
38
	public const OPTION_OBJECTS_FOR_MAPS = 1;
39
	/**
40
	 * @since 1.7.0
41
	 * @deprecated since 2.5 use OPTION_SERIALIZE_SNAKS_WITHOUT_HASH
42
	 */
43
	public const OPTION_SERIALIZE_MAIN_SNAKS_WITHOUT_HASH = 2;
44
	/**
45
	 * @since 1.7.0
46
	 * @deprecated since 2.5 use OPTION_SERIALIZE_SNAKS_WITHOUT_HASH
47
	 */
48
	public const OPTION_SERIALIZE_QUALIFIER_SNAKS_WITHOUT_HASH = 4;
49
	/**
50
	 * @since 1.7.0
51
	 * @deprecated since 2.5 use OPTION_SERIALIZE_SNAKS_WITHOUT_HASH
52
	 */
53
	public const OPTION_SERIALIZE_REFERENCE_SNAKS_WITHOUT_HASH = 8;
54
	/**
55
	 * Omit hashes when serializing snaks.
56
	 * @since 2.5.0
57
	 */
58
	public const OPTION_SERIALIZE_SNAKS_WITHOUT_HASH = 14; /* =
59
		self::OPTION_SERIALIZE_MAIN_SNAKS_WITHOUT_HASH |
60
		self::OPTION_SERIALIZE_QUALIFIER_SNAKS_WITHOUT_HASH |
61
		self::OPTION_SERIALIZE_REFERENCE_SNAKS_WITHOUT_HASH; */
62
63
	/**
64
	 * @var int
65
	 */
66
	private $options;
67
68
	/**
69
	 * @var Serializer
70
	 */
71
	private $dataValueSerializer;
72
73
	/**
74
	 * @param Serializer $dataValueSerializer serializer for DataValue objects
75
	 * @param int $options set multiple with bitwise or
76
	 *
77
	 * @throws InvalidArgumentException
78
	 */
79 52
	public function __construct( Serializer $dataValueSerializer, $options = 0 ) {
80 52
		if ( !is_int( $options ) ) {
81 1
			throw new InvalidArgumentException( '$options must be an integer' );
82
		}
83
84 51
		$this->dataValueSerializer = $dataValueSerializer;
85 51
		$this->options = $options;
86 51
	}
87
88
	/**
89
	 * @return bool
90
	 */
91 38
	private function shouldUseObjectsForMaps() {
92 38
		return (bool)( $this->options & self::OPTION_OBJECTS_FOR_MAPS );
93
	}
94
95
	/**
96
	 * @return bool
97
	 */
98 22
	private function shouldSerializeMainSnaksWithHash() {
99 22
		return !(bool)( $this->options & self::OPTION_SERIALIZE_MAIN_SNAKS_WITHOUT_HASH );
0 ignored issues
show
Deprecated Code introduced by
The constant Wikibase\DataModel\Seria...MAIN_SNAKS_WITHOUT_HASH has been deprecated with message: since 2.5 use OPTION_SERIALIZE_SNAKS_WITHOUT_HASH

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
100
	}
101
102
	/**
103
	 * @return bool
104
	 */
105 22
	private function shouldSerializeQualifierSnaksWithHash() {
106 22
		return !(bool)( $this->options & self::OPTION_SERIALIZE_QUALIFIER_SNAKS_WITHOUT_HASH );
0 ignored issues
show
Deprecated Code introduced by
The constant Wikibase\DataModel\Seria...FIER_SNAKS_WITHOUT_HASH has been deprecated with message: since 2.5 use OPTION_SERIALIZE_SNAKS_WITHOUT_HASH

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
107
	}
108
109
	/**
110
	 * @return bool
111
	 */
112 30
	private function shouldSerializeReferenceSnaksWithHash() {
113 30
		return !(bool)( $this->options & self::OPTION_SERIALIZE_REFERENCE_SNAKS_WITHOUT_HASH );
0 ignored issues
show
Deprecated Code introduced by
The constant Wikibase\DataModel\Seria...ENCE_SNAKS_WITHOUT_HASH has been deprecated with message: since 2.5 use OPTION_SERIALIZE_SNAKS_WITHOUT_HASH

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
114
	}
115
116
	/**
117
	 * @return DispatchableSerializer A serializer that can only serialize Item and Property
118
	 *  objects, but no other entity types. In contexts with custom entity types other than items
119
	 *  and properties this is not what you want. If in doubt, favor a custom
120
	 *  `DispatchingSerializer` containing the exact entity serializers you need.
121
	 */
122 1
	public function newEntitySerializer() {
123 1
		return new DispatchingSerializer( [
124 1
			$this->newItemSerializer(),
125 1
			$this->newPropertySerializer()
126
		] );
127
	}
128
129
	/**
130
	 * Returns a Serializer that can serialize Item objects.
131
	 *
132
	 * @since 2.1
133
	 *
134
	 * @return DispatchableSerializer
135
	 */
136 8
	public function newItemSerializer() {
137 8
		return new ItemSerializer(
138 8
			$this->newTermListSerializer(),
139 8
			$this->newAliasGroupListSerializer(),
140 8
			$this->newStatementListSerializer(),
141 8
			$this->newSiteLinkSerializer(),
142 8
			$this->shouldUseObjectsForMaps()
143
		);
144
	}
145
146
	/**
147
	 * Returns a Serializer that can serialize Property objects.
148
	 *
149
	 * @since 2.1
150
	 *
151
	 * @return DispatchableSerializer
152
	 */
153 3
	public function newPropertySerializer() {
154 3
		return new PropertySerializer(
155 3
			$this->newTermListSerializer(),
156 3
			$this->newAliasGroupListSerializer(),
157 3
			$this->newStatementListSerializer()
158
		);
159
	}
160
161
	/**
162
	 * Returns a Serializer that can serialize SiteLink objects.
163
	 *
164
	 * @return Serializer
165
	 */
166 12
	public function newSiteLinkSerializer() {
167 12
		return new SiteLinkSerializer();
168
	}
169
170
	/**
171
	 * Returns a Serializer that can serialize StatementList objects.
172
	 *
173
	 * @since 1.4
174
	 *
175
	 * @return Serializer
176
	 */
177 14
	public function newStatementListSerializer() {
178 14
		return new StatementListSerializer(
179 14
			$this->newStatementSerializer(),
180 14
			$this->shouldUseObjectsForMaps()
181
		);
182
	}
183
184
	/**
185
	 * Returns a Serializer that can serialize Statement objects.
186
	 *
187
	 * @since 1.4
188
	 *
189
	 * @return DispatchableSerializer
190
	 */
191 22
	public function newStatementSerializer() {
192 22
		return new StatementSerializer(
193 22
			$this->newSnakSerializer( $this->shouldSerializeMainSnaksWithHash() ),
194 22
			$this->newSnakListSerializer( $this->shouldSerializeQualifierSnaksWithHash() ),
195 22
			$this->newReferencesSerializer()
196
		);
197
	}
198
199
	/**
200
	 * Returns a Serializer that can serialize ReferenceList objects.
201
	 *
202
	 * @return Serializer
203
	 */
204 26
	public function newReferencesSerializer() {
205 26
		return new ReferenceListSerializer( $this->newReferenceSerializer() );
206
	}
207
208
	/**
209
	 * Returns a Serializer that can serialize Reference objects.
210
	 *
211
	 * @return Serializer
212
	 */
213 30
	public function newReferenceSerializer() {
214 30
		return new ReferenceSerializer(
215 30
			$this->newSnakListSerializer(
216 30
				$this->shouldSerializeReferenceSnaksWithHash()
217
			)
218
		);
219
	}
220
221
	/**
222
	 * Returns a Serializer that can serialize SnakList objects.
223
	 *
224
	 * @param bool $serializeSnaksWithHash
225
	 *
226
	 * @since 1.4
227
	 *
228
	 * @return Serializer
229
	 */
230 36
	public function newSnakListSerializer( $serializeSnaksWithHash = true ) {
231 36
		return new SnakListSerializer(
232 36
			$this->newSnakSerializer( $serializeSnaksWithHash ),
233 36
			$this->shouldUseObjectsForMaps()
234
		);
235
	}
236
237
	/**
238
	 * Returns a Serializer that can serialize Snak objects.
239
	 *
240
	 * @param bool $serializeWithHash
241
	 *
242
	 * @return Serializer
243
	 */
244 43
	public function newSnakSerializer( $serializeWithHash = true ) {
245 43
		return new SnakSerializer( $this->dataValueSerializer, $serializeWithHash );
246
	}
247
248
	/**
249
	 * Returns a Serializer that can serialize TypedSnak objects.
250
	 *
251
	 * @param bool $serializeWithHash
252
	 *
253
	 * @since 1.3
254
	 *
255
	 * @return Serializer
256
	 */
257 1
	public function newTypedSnakSerializer( $serializeWithHash = true ) {
258 1
		return new TypedSnakSerializer( $this->newSnakSerializer( $serializeWithHash ) );
259
	}
260
261
	/**
262
	 * Returns a Serializer that can serialize Term objects.
263
	 *
264
	 * @since 1.5
265
	 *
266
	 * @return Serializer
267
	 */
268 12
	public function newTermSerializer() {
269 12
		return new TermSerializer();
270
	}
271
272
	/**
273
	 * Returns a Serializer that can serialize TermList objects.
274
	 *
275
	 * @since 1.5
276
	 *
277
	 * @return Serializer
278
	 */
279 11
	public function newTermListSerializer() {
280 11
		return new TermListSerializer( $this->newTermSerializer(), $this->shouldUseObjectsForMaps() );
281
	}
282
283
	/**
284
	 * Returns a Serializer that can serialize AliasGroup objects.
285
	 *
286
	 * @since 1.6
287
	 *
288
	 * @return Serializer
289
	 */
290 12
	public function newAliasGroupSerializer() {
291 12
		return new AliasGroupSerializer();
292
	}
293
294
	/**
295
	 * Returns a Serializer that can serialize AliasGroupList objects.
296
	 *
297
	 * @since 1.5
298
	 *
299
	 * @return Serializer
300
	 */
301 11
	public function newAliasGroupListSerializer() {
302 11
		return new AliasGroupListSerializer(
303 11
			$this->newAliasGroupSerializer(),
304 11
			$this->shouldUseObjectsForMaps()
305
		);
306
	}
307
308
}
309