-
-
Notifications
You must be signed in to change notification settings - Fork 36.2k
Truncate password before sending it to bcrypt #155950
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
Conversation
|
/CC @pantherale0 |
|
Worth just mentioning the background to the limit for those who may be unaware, this sums it up nicely: https://security.stackexchange.com/a/184090 |
frenck
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly, I'm not sure on this approach. This is basically masking the issue, which IMHO isn't the right approach.
Why would we just magically ignore part of the password instead of raising awareness?
MartinHjelmare
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a test with a password that is longer than 72 characters.
Why didn't we catch this when preparing the library bump where the major version of the library was bumped? It was clearly written in the changelog.
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
|
@frenck masking it silently was the case before too. I think we should address that separately. |
The goal with this PR was to just restore the previous state as fast as possible. Yes, we would tell our users that their password is too long. However that might require a bit more thought and might be best for a separate PR. E.g. I believe the login form is used for both user creation and login itself. So while we could certainly add a length validator, that would block existing users with these long passwords. Not sure we can do much more than raising an issue and wait for users to change their passwords themselves. If someone has a better idea for a migration, I'm all ears. core/homeassistant/auth/providers/homeassistant.py Lines 424 to 431 in 5237dc0
My added test already covers it or am I missing something? Maybe I should rename the test case to pwd_truncated = "hWwjDpFiYtDTaaMbXdjzeuKAPI3G4Di2mC92" * 4 # 72 chars
long_pwd = pwd_truncated * 2 # 144 chars
data.add_auth("test-user", long_pwd)
data.validate_login("test-user", long_pwd) |
|
I'm wondering if a migration to argon2 would be appropriate. A period of time where both bcrypt and argon2 is supported with HA, as users sign in etc, the existing bcrypt hash stored is replaced with an argon hash instead. Perhaps that's an architectural discussion. I keep seeing mentions of bcrypt being supported in python for "legacy purposes". Although long term, either way some length validation on the frontend would probably be a requirement to prevent a denial of service attack. |
|
@cdce8p sorry, I must have missed that you added a test already. To be clear, I don't think we should solve anything more in this PR but restore the earlier behavior that trunkated the password silently. We definitely want to improve this but that's for a different PR. Can you shed some light why we didn't catch the breaking change in version 5 of bcrypt when working on the bump PR? |
I probably just missed it or didn't recognize at the time that this would cause issues. The tests all passed so there wasn't any indication to spend more time investigating it and it wasn't caught by the PR review either. To be fair, there are users with really long passwords but they are definitely the exception not the norm. AFAIK we didn't receive any reports about this during the beta either. |
|
But did you note that it was a major version change and that it then should contain at least one breaking change, and read the changelog? I'm digging a bit here, since I was under the impression that this is our process when we do library bumps. Especially when it's a library that we don't maintain ourselves and may not be familiar with the latest changes. |
A lot of breaking changes aren't actually relevant though. E.g. a lot of project will do a new major release when dropping support for an older Python version. I do read the changelogs and almost always also scan the full diff when opening a dependency bump. Sometimes things can slip through. Ideally they are caught during the review but if not, the best I can do is to revert / fix the issue once I'm made aware of it. Not sure there is more I can tell you about it. |
|
Good! Yes, things can slip through. It's important that we follow a good process. Thanks for confirming that was done. |
epenet
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, for patch release.
I too feel this should be followed-up with an architecture discussion about:
- either aligning UI, etc to prevent longer password
- or migrating to a different algorithm
MartinHjelmare
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Proposed change
With bcrypt 5.0 passing a password long than 72 bytes raises a Values. Previously the password was silently truncated.
pyca/bcrypt#1000
Bcrypt was updated in #153325 in preparation for Python 3.14. So it's not easily possible to revert. Truncating it manually as suggested by bcrypt is the next best thing.
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: