Don't hash invalid passwords twice#5655
Open
moritzhoeppner wants to merge 1 commit intoheartcombo:mainfrom
Open
Don't hash invalid passwords twice#5655moritzhoeppner wants to merge 1 commit intoheartcombo:mainfrom
moritzhoeppner wants to merge 1 commit intoheartcombo:mainfrom
Conversation
991c5df to
e406a98
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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_inaction (see #2440 and #2452). Now,Devise::SessionsController#newcreates 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.paranoidis 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_paramsinDevise::SessionsController#new. I think the risk that this breaks something in the application is lower than the risk of changingsign_in_paramsitself.