Issues (40)

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.

lib/PasswordValidator.php (3 issues)

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
 * @author Semih Serhat Karakaya <[email protected]>
4
 * @copyright Copyright (c) 2017, ownCloud GmbH.
5
 * @license AGPL-3.0
6
 *
7
 * This code is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Affero General Public License, version 3,
9
 * as published by the Free Software Foundation.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Affero General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License, version 3,
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
18
 */
19
20
namespace OCA\Security;
21
22
use OC\HintException;
23
use OCP\IL10N;
24
25
class PasswordValidator  {
26
27
	/** @var SecurityConfig */
28
	protected $config;
29
30
	/** @var IL10N */
31
	protected $l;
32
33
	/**
34
	 * PasswordValidator constructor.
35
	 *
36
	 * @param SecurityConfig $config
37
	 * @param IL10N $l
38
	 */
39
	public function __construct(SecurityConfig $config, IL10N $l) {
40
		$this->config = $config;
41
		$this->l = $l;
42
	}
43
44
	/**
45
	 * validate the given password satisfies defined password policy
46
	 *
47
	 * @param string $password
48
	 * @throws HintException
49
	 */
50
	public function validate($password) {
51
		$this->checkPasswordLength($password);
52
		$this->checkNumericCharacters($password);
53
		$this->checkUpperLowerCase($password);
54
		$this->checkSpecialCharacters($password);
55
	}
56
57
	/**
58
	 * validate the given password satisfies defined min length
59
	 *
60
	 * @param string $password
61
	 * @throws HintException
62
	 */
63
	public function checkPasswordLength($password) {
64
		$minPassLength = $this->config->getMinPasswordLength();
65
		if(strlen($password) < $minPassLength) {
66
			$message = 'Password needs to be at least ' . $minPassLength . ' characters long';
67
			$hint = $this->l->t(
68
				'Password needs to be at least %s characters long', [$minPassLength]
69
			);
70
			throw new HintException($message, $hint);
71
		}
72
	}
73
74
	/**
75
	 * validate if password contains at least one upper and one lower case character
76
	 *
77
	 * @param string $password
78
	 * @throws HintException
79
	 */
80 View Code Duplication
	public function checkUpperLowerCase($password) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
81
		$enforceUpperLowerCase= $this->config->getIsUpperLowerCaseEnforced();
82
		if($enforceUpperLowerCase === true && $this->hasUpperAndLowerCase($password) === false) {
83
			$message = 'Password should contain at least one upper and one lower case character.';
84
			$hint = $this->l->t(
85
				'Password should contain at least one upper and one lower case character.'
86
			);
87
			throw new HintException($message, $hint);
88
		}
89
	}
90
91
	/**
92
	 * validate the given password satisfies numeric character policy
93
	 *
94
	 * @param string $password
95
	 * @throws HintException
96
	 */
97 View Code Duplication
	public function checkNumericCharacters($password) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
		$enforceNumericCharacters = $this->config->getIsNumericCharactersEnforced();
99
		if($enforceNumericCharacters === true && $this->hasNumericalCharacters($password) === false) {
100
			$message = 'Password should contain at least one numerical character.';
101
			$hint = $this->l->t(
102
				'Password should contain at least one numerical character.'
103
			);
104
			throw new HintException($message, $hint);
105
		}
106
	}
107
108
	/**
109
	 * check if password contains at least one special character
110
	 *
111
	 * @param string $password
112
	 * @throws HintException
113
	 */
114 View Code Duplication
	public function checkSpecialCharacters($password) {
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
115
		$enforceSpecialCharacters = $this->config->getIsSpecialCharactersEnforced();
116
		if($enforceSpecialCharacters === true && $this->hasSpecialCharacter($password) === false) {
117
			$message = 'Password should contain at least one special character.';
118
			$hint = $this->l->t(
119
				'Password should contain at least one special character.'
120
			);
121
			throw new HintException($message, $hint);
122
		}
123
	}
124
125
	public function hasNumericalCharacters($password) {
126
		return preg_match('/\d/', $password) === 1 ? true : false;
127
	}
128
129
	public function hasUpperAndLowerCase($password) {
130
		$toLower = strtolower($password);
131
		$toUpper = strtoupper($password);
132
		return ($toLower !== $password && $toUpper !== $password) ? true : false;
133
	}
134
135
	public function hasSpecialCharacter($password) {
136
		return (!ctype_alnum($password));
137
	}
138
}