Skip to content

Commit 804c738

Browse files
committed
Merge branch '2.2' into 2.3
* 2.2: bumped Symfony version to 2.2.10 updated VERSION for 2.2.9 update CONTRIBUTORS for 2.2.9 updated CHANGELOG for 2.2.9 [Security] limited the password length passed to encoders assets:install command should mirror .dotfiles (.htaccess) PoFileDumper - PO headers removed whitespaces Conflicts: src/Symfony/Component/HttpKernel/Kernel.php src/Symfony/Component/Security/Core/Encoder/BCryptPasswordEncoder.php
2 parents 54f7d9c + 80a147e commit 804c738

File tree

5 files changed

+42
-3
lines changed

5 files changed

+42
-3
lines changed

Encoder/BCryptPasswordEncoder.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Security\Core\Encoder;
1313

1414
use Symfony\Component\Security\Core\Encoder\BasePasswordEncoder;
15+
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
1516

1617
/**
1718
* @author Elnur Abdurrakhimov <[email protected]>
@@ -64,6 +65,10 @@ public function __construct($cost)
6465
*/
6566
public function encodePassword($raw, $salt)
6667
{
68+
if ($this->isPasswordTooLong($raw)) {
69+
throw new BadCredentialsException('Invalid password.');
70+
}
71+
6772
$options = array('cost' => $this->cost);
6873

6974
if ($salt) {
@@ -78,6 +83,6 @@ public function encodePassword($raw, $salt)
7883
*/
7984
public function isPasswordValid($encoded, $raw, $salt)
8085
{
81-
return password_verify($raw, $encoded);
86+
return !$this->isPasswordTooLong($raw) && password_verify($raw, $encoded);
8287
}
8388
}

Encoder/BasePasswordEncoder.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
*/
2121
abstract class BasePasswordEncoder implements PasswordEncoderInterface
2222
{
23+
const MAX_PASSWORD_LENGTH = 4096;
24+
2325
/**
2426
* Demerges a merge password and salt string.
2527
*
@@ -83,4 +85,14 @@ protected function comparePasswords($password1, $password2)
8385
{
8486
return StringUtils::equals($password1, $password2);
8587
}
88+
89+
/**
90+
* Checks if the password is too long.
91+
*
92+
* @return Boolean true if the password is too long, false otherwise
93+
*/
94+
protected function isPasswordTooLong($password)
95+
{
96+
return strlen($password) > self::MAX_PASSWORD_LENGTH;
97+
}
8698
}

Encoder/MessageDigestPasswordEncoder.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Security\Core\Encoder;
1313

14+
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
15+
1416
/**
1517
* MessageDigestPasswordEncoder uses a message digest algorithm.
1618
*
@@ -41,6 +43,10 @@ public function __construct($algorithm = 'sha512', $encodeHashAsBase64 = true, $
4143
*/
4244
public function encodePassword($raw, $salt)
4345
{
46+
if ($this->isPasswordTooLong($raw)) {
47+
throw new BadCredentialsException('Invalid password.');
48+
}
49+
4450
if (!in_array($this->algorithm, hash_algos(), true)) {
4551
throw new \LogicException(sprintf('The algorithm "%s" is not supported.', $this->algorithm));
4652
}
@@ -61,6 +67,6 @@ public function encodePassword($raw, $salt)
6167
*/
6268
public function isPasswordValid($encoded, $raw, $salt)
6369
{
64-
return $this->comparePasswords($encoded, $this->encodePassword($raw, $salt));
70+
return !$this->isPasswordTooLong($raw) && $this->comparePasswords($encoded, $this->encodePassword($raw, $salt));
6571
}
6672
}

Encoder/Pbkdf2PasswordEncoder.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Security\Core\Encoder;
1313

14+
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
15+
1416
/**
1517
* Pbkdf2PasswordEncoder uses the PBKDF2 (Password-Based Key Derivation Function 2).
1618
*
@@ -54,6 +56,10 @@ public function __construct($algorithm = 'sha512', $encodeHashAsBase64 = true, $
5456
*/
5557
public function encodePassword($raw, $salt)
5658
{
59+
if ($this->isPasswordTooLong($raw)) {
60+
throw new BadCredentialsException('Invalid password.');
61+
}
62+
5763
if (!in_array($this->algorithm, hash_algos(), true)) {
5864
throw new \LogicException(sprintf('The algorithm "%s" is not supported.', $this->algorithm));
5965
}
@@ -72,7 +78,7 @@ public function encodePassword($raw, $salt)
7278
*/
7379
public function isPasswordValid($encoded, $raw, $salt)
7480
{
75-
return $this->comparePasswords($encoded, $this->encodePassword($raw, $salt));
81+
return !$this->isPasswordTooLong($raw) && $this->comparePasswords($encoded, $this->encodePassword($raw, $salt));
7682
}
7783

7884
private function hashPbkdf2($algorithm, $password, $salt, $iterations, $length = 0)

Encoder/PlaintextPasswordEncoder.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Security\Core\Encoder;
1313

14+
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
15+
1416
/**
1517
* PlaintextPasswordEncoder does not do any encoding.
1618
*
@@ -35,6 +37,10 @@ public function __construct($ignorePasswordCase = false)
3537
*/
3638
public function encodePassword($raw, $salt)
3739
{
40+
if ($this->isPasswordTooLong($raw)) {
41+
throw new BadCredentialsException('Invalid password.');
42+
}
43+
3844
return $this->mergePasswordAndSalt($raw, $salt);
3945
}
4046

@@ -43,6 +49,10 @@ public function encodePassword($raw, $salt)
4349
*/
4450
public function isPasswordValid($encoded, $raw, $salt)
4551
{
52+
if ($this->isPasswordTooLong($raw)) {
53+
return false;
54+
}
55+
4656
$pass2 = $this->mergePasswordAndSalt($raw, $salt);
4757

4858
if (!$this->ignorePasswordCase) {

0 commit comments

Comments
 (0)