fix: raise ProtonCryptoPasswordTooLongError when password exceeds bcrypt's 72-byte limit - #12
Closed
Tadakai wants to merge 1 commit into
Closed
fix: raise ProtonCryptoPasswordTooLongError when password exceeds bcrypt's 72-byte limit#12Tadakai wants to merge 1 commit into
Tadakai wants to merge 1 commit into
Conversation
…ypt's 72-byte limit Instead of letting bcrypt raise a raw ValueError, catch it and raise a descriptive ProtonCryptoPasswordTooLongError so callers can handle it gracefully and show a clear message to the user. Fixes: ValueError: password cannot be longer than 72 bytes
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.
Problem
When a user's password exceeds 72 bytes, bcrypt raises a raw
ValueErrorthat propagates uncaught, causing the login to crash with no clear
feedback to the user.
Solution
This PR catches the
ValueErrorraised bybcrypt.hashpw()inhash_password_3()and re-raises it as a newProtonCryptoPasswordTooLongErrorexception (subclass of
ProtonCryptoError), allowing callers to handleit gracefully and display a meaningful message to the user.
This approach was suggested in PR #10 as the preferred solution over
silently truncating the password.
Changes
proton/session/exceptions.py: addedProtonCryptoPasswordTooLongErrorproton/session/srp/util.py: catchValueErrorfrom bcrypt and raiseProtonCryptoPasswordTooLongError