[11.x] Fix Bcrypt/Argon/Argon2I Hashers not checking database field for nullish value before checking hash compatibility #52297
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backstory:
If we don't check for a nullish or empty value first before checking if a given
$hashedValue
is compatible with our apps algorithm, we'll always throw a runtime exception which means the end user won't receive the normally expected 401/422 or similar failed to authenticate, but rather a 500 server error which makes applications look broken.Started seeing
500
errors for users attempting to login to the app after hash recheck landed in the framework. If a users password field is null or empty in the database they should receive a 401/422 or similar authentication exception/response. This has caused quite a bit of issues as you can imagine the context of a 500 level error vs a 401/422 which is expected if someone is trying to login but hasn't yet set a password.Seems like this was an oversight in this feature being rolled out since we can see some inconsistencies and incorrect logical checks being missing or out of order in the hashing implementations.
Updates
BcryptHasher
ArgonHasher
andArgon2IdHasher
Hash implementations to correctly check if the$hashedValue
field being checked for Hash Algorithm compatibility is notnull
or of length0
. This gives us the behavior before hash verification was added to the framework that will trigger the framework to return early with a proper response offalse
as opposed to a genericRuntimeException
being thrown for a value that should never have been checked for hash algorithm compatibility.To reproduce:
null
in the database500
level error response because of the missing statements being added hereTo show original behavior:
HASH_VERIFY=false
in your.env
null
Thanks for all you do and hopefully this makes it in the framework!