+
Skip to content

Conversation

manthey
Copy link
Member

@manthey manthey commented Sep 26, 2025

bcrypt 5.x makes a change that explicitly warns about truncating long passwords. passlib tests for a bug of some previous version by testing with a long password, which raises this exception.

We currently use passlib for bcrypt and for one-time-passwords (2fa). For the use of bcrypt, the change is straightforward. We can get rid of our _cryptContext object and replace any uses of it (two in model/user.py and one in the rest user.py). This will resolve the current issue with passlib, and won't affect current salts, etc.

The OTP requires a bit more of a refactor, but we can switch to pyotp. I haven't investigated whether this can be done without any major change.

bcrypt 5.x makes a change that explicitly warns about truncating long
passwords.  passlib tests for a bug of some previous version by testing
with a long password, which raises this exception.

We currently use passlib for bcrypt and for one-time-passwords (2fa).
For the use of bcrypt, the change is straightforward.  We can get rid of
our `_cryptContext` object and replace any uses of it (two in
model/user.py and one in the rest user.py).  This will resolve the
current issue with passlib, and won't affect current salts, etc.

The OTP requires a bit more of a refactor, but we can switch to pyotp.
I haven't investigated whether this can be done without any major
change.
@manthey
Copy link
Member Author

manthey commented Sep 26, 2025

@zachmullen The changes to stop using bcrypt through passlib are pretty small. I could do that instead of pinning bcrypt. The work to refactor OTP is probably more, and would need a little investigation. If you think it would be better to stop using bcrypt through passlib right now rather than pinning bcrypt, I'll update this PR.

@manthey manthey requested a review from zachmullen September 26, 2025 16:20
@zachmullen
Copy link
Member

If passlib is truly unmaintained, which it kind of seems to be, we should definitely do the work of removing it at some point. I leave it up to you to figure out if that's now, or some tech debt to resolve later.

Stop using passlib for bcrypt.

There is a slight change to how we speed up tests by using "plaintext"
(this is mimicked from the passlib library, though much simpler).  If we
actually use bcrypt for everything, the tests take nearly twice as long.
@manthey manthey changed the title Pin bcrypt until we switch off of passlib Stop using passlib Sep 26, 2025
@manthey
Copy link
Member Author

manthey commented Sep 26, 2025

So moving off of passlib is pretty straight-foward. I kept the _cryptContext abstraction to keep tests fast -- in some tests ask to use "plaintext" comparisons instead of bcrypt; not doing so nearly doubles the test time.

I've tested the OTP code with Duo. None of the salts or codes have to change from the user's perspective.

# We seem to need a valid_window greater than zero -- in testing,
# Duo shows the otp that pyotp seems to want in the _next_ window; a
# value of 1 matches the default from the old passlib code
totpMatch = totp.verify(otpToken, valid_window=1)
Copy link
Member

Choose a reason for hiding this comment

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

It seems like ±1 is the best practice here so this is fine with me.

@manthey manthey merged commit 9d17127 into master Sep 26, 2025
12 checks passed
@manthey manthey deleted the pin-bcrypt branch September 26, 2025 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载