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/Specials/SpecialSetAliases.php (1 issue)

Labels
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\Repo\Specials;
4
5
use InvalidArgumentException;
6
use MediaWiki\Logger\LoggerFactory;
7
use Wikibase\DataModel\Entity\EntityDocument;
8
use Wikibase\DataModel\Term\AliasesProvider;
9
use Wikibase\Lib\Store\EntityTitleLookup;
10
use Wikibase\Lib\Summary;
11
use Wikibase\Lib\UserInputException;
12
use Wikibase\Repo\ChangeOp\ChangeOps;
13
use Wikibase\Repo\CopyrightMessageBuilder;
14
use Wikibase\Repo\EditEntity\MediawikiEditEntityFactory;
15
use Wikibase\Repo\Store\EntityPermissionChecker;
16
use Wikibase\Repo\SummaryFormatter;
17
use Wikibase\Repo\WikibaseRepo;
18
19
/**
20
 * Special page for setting the aliases of a Wikibase entity.
21
 *
22
 * @license GPL-2.0-or-later
23
 * @author Bene* < [email protected] >
24
 */
25
class SpecialSetAliases extends SpecialModifyTerm {
0 ignored issues
show
There is one abstract method getName in this class; you could implement it, or declare this class as abstract.
Loading history...
26
27
	public function __construct(
28
		SpecialPageCopyrightView $copyrightView,
29
		SummaryFormatter $summaryFormatter,
30
		EntityTitleLookup $entityTitleLookup,
31
		MediawikiEditEntityFactory $editEntityFactory,
32
		EntityPermissionChecker $entityPermissionChecker
33
	) {
34
		parent::__construct(
35
			'SetAliases',
36
			$copyrightView,
37
			$summaryFormatter,
38
			$entityTitleLookup,
39
			$editEntityFactory,
40
			$entityPermissionChecker
41
		);
42
	}
43
44
	public static function factory(): self {
45
		$wikibaseRepo = WikibaseRepo::getDefaultInstance();
46
47
		$settings = $wikibaseRepo->getSettings();
48
		$copyrightView = new SpecialPageCopyrightView(
49
			new CopyrightMessageBuilder(),
50
			$settings->getSetting( 'dataRightsUrl' ),
51
			$settings->getSetting( 'dataRightsText' )
52
		);
53
54
		return new self(
55
			$copyrightView,
56
			$wikibaseRepo->getSummaryFormatter(),
57
			$wikibaseRepo->getEntityTitleLookup(),
58
			$wikibaseRepo->newEditEntityFactory(),
59
			$wikibaseRepo->getEntityPermissionChecker()
60
		);
61
	}
62
63
	public function doesWrites() {
64
		return true;
65
	}
66
67
	/**
68
	 * @see SpecialModifyTerm::validateInput
69
	 *
70
	 * @return bool
71
	 */
72
	protected function validateInput() {
73
		if ( !parent::validateInput() ) {
74
			return false;
75
		}
76
77
		return $this->getBaseRevision()->getEntity() instanceof AliasesProvider;
78
	}
79
80
	/**
81
	 * @see SpecialModifyTerm::getPostedValue()
82
	 *
83
	 * @return string|null
84
	 */
85
	protected function getPostedValue() {
86
		return $this->getRequest()->getVal( 'aliases' );
87
	}
88
89
	/**
90
	 * @see SpecialModifyTerm::getValue()
91
	 *
92
	 * @param EntityDocument $entity
93
	 * @param string $languageCode
94
	 *
95
	 * @throws InvalidArgumentException
96
	 * @return string
97
	 */
98
	protected function getValue( EntityDocument $entity, $languageCode ) {
99
		if ( !( $entity instanceof AliasesProvider ) ) {
100
			throw new InvalidArgumentException( '$entity must be an AliasesProvider' );
101
		}
102
		$aliases = $entity->getAliasGroups();
103
		if ( $aliases->hasGroupForLanguage( $languageCode ) ) {
104
			return implode( '|', $aliases->getByLanguage( $languageCode )->getAliases() );
105
		}
106
		return '';
107
	}
108
109
	/**
110
	 * @see SpecialModifyTerm::setValue()
111
	 *
112
	 * @param EntityDocument $entity
113
	 * @param string $languageCode
114
	 * @param string $value
115
	 *
116
	 * @throws UserInputException|InvalidArgumentException
117
	 * @return Summary
118
	 * @suppress PhanTypeMismatchArgument
119
	 */
120
	protected function setValue( EntityDocument $entity, $languageCode, $value ) {
121
		if ( !( $entity instanceof AliasesProvider ) ) {
122
			throw new InvalidArgumentException( '$entity must be an AliasesProvider' );
123
		}
124
125
		$summary = new Summary( 'wbsetaliases' );
126
		if ( $value === '' ) {
127
			$aliases = $entity->getAliasGroups()->getByLanguage( $languageCode )->getAliases();
128
			$changeOp = $this->termChangeOpFactory->newRemoveAliasesOp( $languageCode, $aliases );
129
		} else {
130
			$this->assertNoPipeCharacterInAliases( $entity, $languageCode );
131
			$changeOp = $this->termChangeOpFactory->newSetAliasesOp( $languageCode, explode( '|', $value ) );
132
		}
133
134
		$fingerprintChangeOp = $this->termChangeOpFactory->newFingerprintChangeOp( new ChangeOps( [ $changeOp ] ) );
135
136
		$this->applyChangeOp( $fingerprintChangeOp, $entity, $summary );
137
138
		return $summary;
139
	}
140
141
	/**
142
	 * Screams and throws an error if any of existing aliases has pipe character
143
	 *
144
	 * @param EntityDocument $entity
145
	 * @param string $languageCode
146
	 *
147
	 * @throws UserInputException
148
	 * @suppress PhanTypeMismatchDeclaredParam Intersection type
149
	 */
150
	private function assertNoPipeCharacterInAliases( AliasesProvider $entity, $languageCode ) {
151
		$aliases = $entity->getAliasGroups();
152
		if ( !$aliases->hasGroupForLanguage( $languageCode ) ) {
153
			return;
154
		}
155
		$aliasesInLang = $entity->getAliasGroups()->getByLanguage( $languageCode )->getAliases();
156
157
		foreach ( $aliasesInLang as $alias ) {
158
			if ( strpos( $alias, '|' ) !== false ) {
159
				$logger = LoggerFactory::getInstance( 'Wikibase' );
160
				$logger->error( 'Special:SetAliases attempt to save pipes in aliases' );
161
				throw new UserInputException(
162
					'wikibase-wikibaserepopage-pipe-in-alias',
163
					[],
164
					$this->msg( 'wikibase-wikibaserepopage-pipe-in-alias' )->text()
165
				);
166
			}
167
		}
168
	}
169
170
}
171