Skip to content
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

[11.x] Fix Bcrypt/Argon/Argon2I Hashers not checking database field for nullish value before checking hash compatibility #52297

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Illuminate/Hashing/Argon2IdHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class Argon2IdHasher extends ArgonHasher
*/
public function check(#[\SensitiveParameter] $value, $hashedValue, array $options = [])
{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like a logic error to check for the hash compatibility before checking if the hashed value is even non-null or empty.

the original if statement would never be reached. contrast to the other hashing implementations that were missing this entirely

if (is_null($hashedValue) || strlen($hashedValue) === 0) {
            return false;
        }

if ($this->verifyAlgorithm && ! $this->isUsingCorrectAlgorithm($hashedValue)) {
throw new RuntimeException('This password does not use the Argon2id algorithm.');
}

if (is_null($hashedValue) || strlen($hashedValue) === 0) {
return false;
}

if ($this->verifyAlgorithm && ! $this->isUsingCorrectAlgorithm($hashedValue)) {
throw new RuntimeException('This password does not use the Argon2id algorithm.');
}

return password_verify($value, $hashedValue);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Illuminate/Hashing/ArgonHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ protected function algorithm()
*/
public function check(#[\SensitiveParameter] $value, $hashedValue, array $options = [])
{
if (is_null($hashedValue) || strlen($hashedValue) === 0) {
return false;
}

if ($this->verifyAlgorithm && ! $this->isUsingCorrectAlgorithm($hashedValue)) {
throw new RuntimeException('This password does not use the Argon2i algorithm.');
}
Expand Down
4 changes: 4 additions & 0 deletions src/Illuminate/Hashing/BcryptHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public function make(#[\SensitiveParameter] $value, array $options = [])
*/
public function check(#[\SensitiveParameter] $value, $hashedValue, array $options = [])
{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we don't check for a nullish or empty value first, we'll always throw a runtime exception which means the end user won't receive the normally expected 401 or similar failed to authenticate, but rather a 500 server error which makes applications look broken

if (is_null($hashedValue) || strlen($hashedValue) === 0) {
return false;
}

if ($this->verifyAlgorithm && ! $this->isUsingCorrectAlgorithm($hashedValue)) {
throw new RuntimeException('This password does not use the Bcrypt algorithm.');
}
Expand Down