Don't hash invalid passwords twice #5655
Open
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.
In order to avoid "unpermitted parameters" errors, the password parameter is permitted by default for the
sign_in
action (see #2440 and #2452). Now,Devise::SessionsController#new
creates a new resource with the permitted parameters before cleaning up the password. This means that an invalid password is hashed twice: The first time - as it should be - when it is validated withDevise::Encryptor.compare
(invoked byresource.valid_password?
), and then a second time withDevise::Encryptor.digest
(invoked byDevise::SessionsController#new
). Something similar happens if the authentication key is invalid andDevise.paranoid
is true.I think this is problematic as the number of stretches is always a compromise between password security on the one hand and performance and the danger of generating DoS opportunities on the other hand. Fixing this would probably allow some applications to increase the number of stretches.
My solution is to simply remove the password from the return value of
sign_in_params
inDevise::SessionsController#new
. I think the risk that this breaks something in the application is lower than the risk of changingsign_in_params
itself.