Skip to content

Conversation

@cdce8p
Copy link
Member

@cdce8p cdce8p commented Nov 6, 2025

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

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@cdce8p cdce8p added this to the 2025.11.1 milestone Nov 6, 2025
@cdce8p cdce8p requested a review from a team as a code owner November 6, 2025 14:20
@home-assistant home-assistant bot added bugfix cla-signed core small-pr PRs with less than 30 lines. labels Nov 6, 2025
@cdce8p
Copy link
Member Author

cdce8p commented Nov 6, 2025

/CC @pantherale0

@pantherale0
Copy link
Contributor

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

Copy link
Member

@frenck frenck left a 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?

Copy link
Member

@MartinHjelmare MartinHjelmare left a 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.

@home-assistant home-assistant bot marked this pull request as draft November 7, 2025 08:29
@home-assistant
Copy link

home-assistant bot commented Nov 7, 2025

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@MartinHjelmare
Copy link
Member

@frenck masking it silently was the case before too. I think we should address that separately.

@cdce8p
Copy link
Member Author

cdce8p commented Nov 7, 2025

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.

return self.async_show_form(
step_id="init",
data_schema=vol.Schema(
{
vol.Required("username"): str,
vol.Required("password"): str,
}
),

Please add a test with a password that is longer than 72 characters.

My added test already covers it or am I missing something? Maybe I should rename the test case to test_long_passwords?

    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)

@cdce8p cdce8p marked this pull request as ready for review November 7, 2025 10:05
@pantherale0
Copy link
Contributor

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.

@MartinHjelmare
Copy link
Member

@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?

@cdce8p
Copy link
Member Author

cdce8p commented Nov 7, 2025

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.

@MartinHjelmare
Copy link
Member

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.

@cdce8p
Copy link
Member Author

cdce8p commented Nov 7, 2025

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?

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.

@MartinHjelmare
Copy link
Member

Good! Yes, things can slip through. It's important that we follow a good process. Thanks for confirming that was done.

Copy link
Contributor

@epenet epenet left a 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

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@frenck frenck merged commit 67156d1 into home-assistant:dev Nov 7, 2025
66 checks passed
@frenck frenck mentioned this pull request Nov 7, 2025
@cdce8p cdce8p deleted the bcrypt-truncate-pwd branch November 8, 2025 10:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HA login not possible with passwords longer than 72 characters after 2025.11.0 update

5 participants