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.

AbstractPasswordPrimaryAuthenticationProvider.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
 * This program is free software; you can redistribute it and/or modify
4
 * it under the terms of the GNU General Public License as published by
5
 * the Free Software Foundation; either version 2 of the License, or
6
 * (at your option) any later version.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
 * GNU General Public License for more details.
12
 *
13
 * You should have received a copy of the GNU General Public License along
14
 * with this program; if not, write to the Free Software Foundation, Inc.,
15
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
 * http://www.gnu.org/copyleft/gpl.html
17
 *
18
 * @file
19
 * @ingroup Auth
20
 */
21
22
namespace MediaWiki\Auth;
23
24
use Password;
25
use PasswordFactory;
26
use Status;
27
28
/**
29
 * Basic framework for a primary authentication provider that uses passwords
30
 * @ingroup Auth
31
 * @since 1.27
32
 */
33
abstract class AbstractPasswordPrimaryAuthenticationProvider
34
	extends AbstractPrimaryAuthenticationProvider
0 ignored issues
show
The extends keyword must be on the same line as the class name
Loading history...
35
{
36
	/** @var bool Whether this provider should ABSTAIN (false) or FAIL (true) on password failure */
37
	protected $authoritative;
38
39
	private $passwordFactory = null;
40
41
	/**
42
	 * @param array $params Settings
43
	 *  - authoritative: Whether this provider should ABSTAIN (false) or FAIL
44
	 *    (true) on password failure
45
	 */
46
	public function __construct( array $params = [] ) {
47
		$this->authoritative = !isset( $params['authoritative'] ) || (bool)$params['authoritative'];
48
	}
49
50
	/**
51
	 * Get the PasswordFactory
52
	 * @return PasswordFactory
53
	 */
54
	protected function getPasswordFactory() {
55
		if ( $this->passwordFactory === null ) {
56
			$this->passwordFactory = new PasswordFactory();
57
			$this->passwordFactory->init( $this->config );
58
		}
59
		return $this->passwordFactory;
60
	}
61
62
	/**
63
	 * Get a Password object from the hash
64
	 * @param string $hash
65
	 * @return Password
66
	 */
67
	protected function getPassword( $hash ) {
68
		$passwordFactory = $this->getPasswordFactory();
69
		try {
70
			return $passwordFactory->newFromCiphertext( $hash );
71
		} catch ( \PasswordError $e ) {
72
			$class = static::class;
73
			$this->logger->debug( "Invalid password hash in {$class}::getPassword()" );
74
			return $passwordFactory->newFromCiphertext( null );
75
		}
76
	}
77
78
	/**
79
	 * Return the appropriate response for failure
80
	 * @param PasswordAuthenticationRequest $req
81
	 * @return AuthenticationResponse
82
	 */
83
	protected function failResponse( PasswordAuthenticationRequest $req ) {
84
		if ( $this->authoritative ) {
85
			return AuthenticationResponse::newFail(
86
				wfMessage( $req->password === '' ? 'wrongpasswordempty' : 'wrongpassword' )
87
			);
88
		} else {
89
			return AuthenticationResponse::newAbstain();
90
		}
91
	}
92
93
	/**
94
	 * Check that the password is valid
95
	 *
96
	 * This should be called *before* validating the password. If the result is
97
	 * not ok, login should fail immediately.
98
	 *
99
	 * @param string $username
100
	 * @param string $password
101
	 * @return Status
102
	 */
103
	protected function checkPasswordValidity( $username, $password ) {
104
		return \User::newFromName( $username )->checkPasswordValidity( $password );
105
	}
106
107
	/**
108
	 * Check if the password should be reset
109
	 *
110
	 * This should be called after a successful login. It sets 'reset-pass'
111
	 * authentication data if necessary, see
112
	 * ResetPassSecondaryAuthenticationProvider.
113
	 *
114
	 * @param string $username
115
	 * @param Status $status From $this->checkPasswordValidity()
116
	 * @param mixed $data Passed through to $this->getPasswordResetData()
117
	 */
118
	protected function setPasswordResetFlag( $username, Status $status, $data = null ) {
119
		$reset = $this->getPasswordResetData( $username, $data );
120
121
		if ( !$reset && $this->config->get( 'InvalidPasswordReset' ) && !$status->isGood() ) {
122
			$reset = (object)[
123
				'msg' => $status->getMessage( 'resetpass-validity-soft' ),
124
				'hard' => false,
125
			];
126
		}
127
128
		if ( $reset ) {
129
			$this->manager->setAuthenticationSessionData( 'reset-pass', $reset );
130
		}
131
	}
132
133
	/**
134
	 * Get password reset data, if any
135
	 *
136
	 * @param string $username
137
	 * @param mixed $data
138
	 * @return object|null { 'hard' => bool, 'msg' => Message }
139
	 */
140
	protected function getPasswordResetData( $username, $data ) {
141
		return null;
142
	}
143
144
	/**
145
	 * Get expiration date for a new password, if any
146
	 *
147
	 * @param string $username
148
	 * @return string|null
149
	 */
150
	protected function getNewPasswordExpiry( $username ) {
151
		$days = $this->config->get( 'PasswordExpirationDays' );
152
		$expires = $days ? wfTimestamp( TS_MW, time() + $days * 86400 ) : null;
153
154
		// Give extensions a chance to force an expiration
155
		\Hooks::run( 'ResetPasswordExpiration', [ \User::newFromName( $username ), &$expires ] );
156
157
		return $expires;
158
	}
159
160
	public function getAuthenticationRequests( $action, array $options ) {
161
		switch ( $action ) {
162
			case AuthManager::ACTION_LOGIN:
163
			case AuthManager::ACTION_REMOVE:
164
			case AuthManager::ACTION_CREATE:
165
			case AuthManager::ACTION_CHANGE:
166
				return [ new PasswordAuthenticationRequest() ];
167
			default:
168
				return [];
169
		}
170
	}
171
}
172