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

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
declare( strict_types = 1 );
4
5
namespace Wikibase\Repo\Api;
6
7
use ApiBase;
8
use ApiMain;
9
use Wikibase\DataModel\Services\Statement\StatementGuidParser;
10
use Wikibase\Repo\ChangeOp\StatementChangeOpFactory;
11
use Wikibase\Repo\WikibaseRepo;
12
13
/**
14
 * API module for setting the DataValue contained by the main snak of a claim.
15
 *
16
 * @license GPL-2.0-or-later
17
 * @author Jeroen De Dauw < [email protected] >
18
 * @author Tobias Gritschacher < [email protected] >
19
 */
20
class SetClaimValue extends ApiBase {
21
22
	use FederatedPropertyApiValidatorTrait;
23
24
	/**
25
	 * @var StatementChangeOpFactory
26
	 */
27
	private $statementChangeOpFactory;
28
29
	/**
30
	 * @var ApiErrorReporter
31
	 */
32
	protected $errorReporter;
33
34
	/**
35
	 * @var StatementModificationHelper
36
	 */
37
	private $modificationHelper;
38
39
	/**
40
	 * @var StatementGuidParser
41
	 */
42
	private $guidParser;
43
44
	/**
45
	 * @var ResultBuilder
46
	 */
47
	private $resultBuilder;
48
49
	/**
50
	 * @var EntitySavingHelper
51
	 */
52
	private $entitySavingHelper;
53
54
	public function __construct(
55
		ApiMain $mainModule,
56
		string $moduleName,
57
		ApiErrorReporter $errorReporter,
58
		StatementChangeOpFactory $statementChangeOpFactory,
59
		StatementModificationHelper $modificationHelper,
60
		StatementGuidParser $guidParser,
61
		callable $resultBuilderInstantiator,
62
		callable $entitySavingHelperInstantiator,
63
		bool $federatedPropertiesEnabled
64
	) {
65
		parent::__construct( $mainModule, $moduleName );
66
67
		$this->errorReporter = $errorReporter;
68
		$this->statementChangeOpFactory = $statementChangeOpFactory;
69
		$this->modificationHelper = $modificationHelper;
70
		$this->guidParser = $guidParser;
71
		$this->resultBuilder = $resultBuilderInstantiator( $this );
72
		$this->entitySavingHelper = $entitySavingHelperInstantiator( $this );
73
		$this->federatedPropertiesEnabled = $federatedPropertiesEnabled;
74
	}
75
76
	public static function factory( ApiMain $mainModule, string $moduleName ): self {
77
		$wikibaseRepo = WikibaseRepo::getDefaultInstance();
78
		$apiHelperFactory = $wikibaseRepo->getApiHelperFactory( $mainModule->getContext() );
79
		$changeOpFactoryProvider = $wikibaseRepo->getChangeOpFactoryProvider();
80
81
		$modificationHelper = new StatementModificationHelper(
82
			$wikibaseRepo->getSnakFactory(),
83
			$wikibaseRepo->getEntityIdParser(),
84
			$wikibaseRepo->getStatementGuidValidator(),
85
			$apiHelperFactory->getErrorReporter( $mainModule )
86
		);
87
88
		return new self(
89
			$mainModule,
90
			$moduleName,
91
			$apiHelperFactory->getErrorReporter( $mainModule ),
92
			$changeOpFactoryProvider->getStatementChangeOpFactory(),
93
			$modificationHelper,
94
			$wikibaseRepo->getStatementGuidParser(),
95
			function ( $module ) use ( $apiHelperFactory ) {
96
				return $apiHelperFactory->getResultBuilder( $module );
97
			},
98
			function ( $module ) use ( $apiHelperFactory ) {
99
				return $apiHelperFactory->getEntitySavingHelper( $module );
100
			},
101
			$wikibaseRepo->inFederatedPropertyMode()
102
		);
103
	}
104
105
	/**
106
	 * @inheritDoc
107
	 */
108
	public function execute(): void {
109
		$params = $this->extractRequestParams();
110
		$this->validateParameters( $params );
111
112
		$this->logFeatureUsage( 'action=wbsetclaimvalue' );
113
114
		$guid = $params['claim'];
115
		$entityId = $this->guidParser->parse( $guid )->getEntityId();
116
		$this->validateAlteringEntityById( $entityId );
117
		$entity = $this->entitySavingHelper->loadEntity( $entityId );
118
119
		$claim = $this->modificationHelper->getStatementFromEntity( $guid, $entity );
120
121
		$snak = $this->modificationHelper->getSnakInstance( $params, $claim->getPropertyId() );
122
123
		$summary = $this->modificationHelper->createSummary( $params, $this );
124
125
		$changeOp = $this->statementChangeOpFactory->newSetMainSnakOp( $guid, $snak );
126
127
		$this->modificationHelper->applyChangeOp( $changeOp, $entity, $summary );
128
129
		$status = $this->entitySavingHelper->attemptSaveEntity( $entity, $summary );
130
		$this->resultBuilder->addRevisionIdFromStatusToResult( $status, 'pageinfo' );
131
		$this->resultBuilder->markSuccess();
132
		$this->resultBuilder->addStatement( $claim );
133
	}
134
135
	/**
136
	 * @param array $params
137
	 */
138
	private function validateParameters( array $params ): void {
139
		if ( !( $this->modificationHelper->validateStatementGuid( $params['claim'] ) ) ) {
140
			$this->errorReporter->dieError( 'Invalid claim guid', 'invalid-guid' );
0 ignored issues
show
Deprecated Code introduced by
The method Wikibase\Repo\Api\ApiErrorReporter::dieError() has been deprecated with message: Use dieWithError() instead.

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
141
		}
142
	}
143
144
	/**
145
	 * @inheritDoc
146
	 */
147
	public function isWriteMode(): bool {
148
		return true;
149
	}
150
151
	/**
152
	 * @see ApiBase::needsToken
153
	 *
154
	 * @return string
155
	 */
156
	public function needsToken(): string {
157
		return 'csrf';
158
	}
159
160
	/**
161
	 * @inheritDoc
162
	 */
163
	protected function getAllowedParams(): array {
164
		return array_merge(
165
			[
166
				'claim' => [
167
					self::PARAM_TYPE => 'string',
168
					self::PARAM_REQUIRED => true,
169
				],
170
				'value' => [
171
					self::PARAM_TYPE => 'text',
172
					self::PARAM_REQUIRED => false,
173
				],
174
				'snaktype' => [
175
					self::PARAM_TYPE => [ 'value', 'novalue', 'somevalue' ],
176
					self::PARAM_REQUIRED => true,
177
				],
178
				'summary' => [
179
					self::PARAM_TYPE => 'string',
180
				],
181
				'tags' => [
182
					self::PARAM_TYPE => 'tags',
183
					self::PARAM_ISMULTI => true,
184
				],
185
				'token' => null,
186
				'baserevid' => [
187
					self::PARAM_TYPE => 'integer',
188
				],
189
				'bot' => false,
190
			],
191
			parent::getAllowedParams()
192
		);
193
	}
194
195
	/**
196
	 * @inheritDoc
197
	 */
198
	protected function getExamplesMessages(): array {
199
		return [
200
			'action=wbsetclaimvalue&claim=Q42$D8404CDA-25E4-4334-AF13-A3290BCD9C0F&snaktype=value'
201
				. '&value={"entity-type":"item","numeric-id":1}&token=foobar&baserevid=7201010'
202
				=> 'apihelp-wbsetclaimvalue-example-1',
203
		];
204
	}
205
206
}
207