Issues (4122)

Security Analysis    not enabled

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.

includes/password/LayeredParameterizedPassword.php (4 issues)

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
 * Implements the LayeredParameterizedPassword class for the MediaWiki software.
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License along
16
 * with this program; if not, write to the Free Software Foundation, Inc.,
17
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
 * http://www.gnu.org/copyleft/gpl.html
19
 *
20
 * @file
21
 */
22
23
/**
24
 * This password hash type layers one or more parameterized password types
25
 * on top of each other.
26
 *
27
 * The underlying types must be parameterized. This wrapping type accumulates
28
 * all the parameters and arguments from each hash and then passes the hash of
29
 * the last layer as the password for the next layer.
30
 *
31
 * @since 1.24
32
 */
33
class LayeredParameterizedPassword extends ParameterizedPassword {
34
	protected function getDelimiter() {
35
		return '!';
36
	}
37
38
	protected function getDefaultParams() {
39
		$params = [];
40
41
		foreach ( $this->config['types'] as $type ) {
42
			$passObj = $this->factory->newFromType( $type );
43
44
			if ( !$passObj instanceof ParameterizedPassword ) {
45
				throw new MWException( 'Underlying type must be a parameterized password.' );
46
			} elseif ( $passObj->getDelimiter() === $this->getDelimiter() ) {
47
				throw new MWException( 'Underlying type cannot use same delimiter as encapsulating type.' );
48
			}
49
50
			$params[] = implode( $passObj->getDelimiter(), $passObj->getDefaultParams() );
51
		}
52
53
		return $params;
54
	}
55
56
	public function crypt( $password ) {
57
		$lastHash = $password;
58 View Code Duplication
		foreach ( $this->config['types'] as $i => $type ) {
59
			// Construct pseudo-hash based on params and arguments
60
			/** @var ParameterizedPassword $passObj */
61
			$passObj = $this->factory->newFromType( $type );
62
63
			$params = '';
64
			$args = '';
65
			if ( $this->params[$i] !== '' ) {
66
				$params = $this->params[$i] . $passObj->getDelimiter();
67
			}
68
			if ( isset( $this->args[$i] ) && $this->args[$i] !== '' ) {
69
				$args = $this->args[$i] . $passObj->getDelimiter();
70
			}
71
			$existingHash = ":$type:" . $params . $args . $this->hash;
72
73
			// Hash the last hash with the next type in the layer
74
			$passObj = $this->factory->newFromCiphertext( $existingHash );
75
			$passObj->crypt( $lastHash );
76
77
			// Move over the params and args
78
			$this->params[$i] = implode( $passObj->getDelimiter(), $passObj->params );
0 ignored issues
show
The property params does not seem to exist in Password.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
79
			$this->args[$i] = implode( $passObj->getDelimiter(), $passObj->args );
0 ignored issues
show
The property args does not seem to exist in Password.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
80
			$lastHash = $passObj->hash;
81
		}
82
83
		$this->hash = $lastHash;
84
	}
85
86
	/**
87
	 * Finish the hashing of a partially hashed layered hash
88
	 *
89
	 * Given a password hash that is hashed using the first layer of this object's
90
	 * configuration, perform the remaining layers of password hashing in order to
91
	 * get an updated hash with all the layers.
92
	 *
93
	 * @param ParameterizedPassword $passObj Password hash of the first layer
94
	 *
95
	 * @throws MWException If the first parameter is not of the correct type
96
	 */
97
	public function partialCrypt( ParameterizedPassword $passObj ) {
98
		$type = $passObj->config['type'];
99
		if ( $type !== $this->config['types'][0] ) {
100
			throw new MWException( 'Only a hash in the first layer can be finished.' );
101
		}
102
103
		// Gather info from the existing hash
104
		$this->params[0] = implode( $passObj->getDelimiter(), $passObj->params );
105
		$this->args[0] = implode( $passObj->getDelimiter(), $passObj->args );
106
		$lastHash = $passObj->hash;
107
108
		// Layer the remaining types
109 View Code Duplication
		foreach ( $this->config['types'] as $i => $type ) {
110
			if ( $i == 0 ) {
111
				continue;
112
			};
113
114
			// Construct pseudo-hash based on params and arguments
115
			/** @var ParameterizedPassword $passObj */
116
			$passObj = $this->factory->newFromType( $type );
117
118
			$params = '';
119
			$args = '';
120
			if ( $this->params[$i] !== '' ) {
121
				$params = $this->params[$i] . $passObj->getDelimiter();
122
			}
123
			if ( isset( $this->args[$i] ) && $this->args[$i] !== '' ) {
124
				$args = $this->args[$i] . $passObj->getDelimiter();
125
			}
126
			$existingHash = ":$type:" . $params . $args . $this->hash;
127
128
			// Hash the last hash with the next type in the layer
129
			$passObj = $this->factory->newFromCiphertext( $existingHash );
130
			$passObj->crypt( $lastHash );
131
132
			// Move over the params and args
133
			$this->params[$i] = implode( $passObj->getDelimiter(), $passObj->params );
0 ignored issues
show
The property params does not seem to exist in Password.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
134
			$this->args[$i] = implode( $passObj->getDelimiter(), $passObj->args );
0 ignored issues
show
The property args does not seem to exist in Password.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
135
			$lastHash = $passObj->hash;
136
		}
137
138
		$this->hash = $lastHash;
139
	}
140
}
141