-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security] Verify if a password encoded with bcrypt is no longer than 72 characters #17055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
||
$this->assertFalse($encoder->isPasswordValid('encoded', str_repeat('a', 5000), 'salt')); | ||
$this->assertFalse($encoder->isPasswordValid($result, str_repeat('a', 73), 'salt')); | ||
$this->assertTrue($encoder->isPasswordValid($result, str_repeat('a', 72), 'salt')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We didn't have this assertion before. Without this there could be no length validation in isPasswordValid()
and the assertion on the line before would pass anyway.
👍 |
@@ -19,6 +19,8 @@ | |||
*/ | |||
class BCryptPasswordEncoder extends BasePasswordEncoder | |||
{ | |||
const MAX_PASSWORD_LENGTH = 72; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could add a comment above this constant to show that this limit is not arbitrary. Something like this:
// When using bcrypt algorithm, PHP's password_hash() truncates the password length to a maximum of 72 chars.
const MAX_PASSWORD_LENGTH = 72;
Thank you @jakzal. |
…longer than 72 characters (jakzal) This PR was merged into the 2.3 branch. Discussion ---------- [Security] Verify if a password encoded with bcrypt is no longer than 72 characters | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17047 | License | MIT | Doc PR | - From the [password_hash() docs](http://php.net/password_hash): > Caution Using the PASSWORD_BCRYPT as the algorithm, will result in the password parameter being truncated to a maximum length of 72 characters. Commits ------- 0a496e7 [Security] Enable bcrypt validation and result length tests on all PHP versions 5c30266 [Security] Verify if a password encoded with bcrypt is no longer than 72 characters
…Christian Flothmann, xabbuh) This PR was merged into the 2.3 branch. Discussion ---------- [Security] skip bcrypt tests on incompatible platforms | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17055 | License | MIT | Doc PR | Not all PHP versions before 5.3.7 have backported fixes that make it possible to use `password_hash()` function. Therefore, we have to skip tests on not supported platforms. Commits ------- 2a6fa7b use requires annotation 65eb188 skip bcrypt tests on incompatible platforms
From the password_hash() docs: