Skip to content
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

Consider raising on passwords longer than 72 bytes #51

Open
reisub opened this issue Feb 16, 2025 · 0 comments
Open

Consider raising on passwords longer than 72 bytes #51

reisub opened this issue Feb 16, 2025 · 0 comments

Comments

@reisub
Copy link

reisub commented Feb 16, 2025

There was a related incident with Okta recently and this blog post does a good job of explaining it and why it's a good idea to disallow hashing passwords over 72 bytes:
https://n0rdy.foo/posts/20250121/okta-bcrypt-lessons-for-better-apis/

Here's a failing test that shows the issue:

test "verify_pass returns false when only first 72 bytes match" do
  pass = "This string is seventy-two characters long. That's also 72 bytes in size"
  hashed_pass = Bcrypt.hash_pwd_salt(pass)
  refute Bcrypt.verify_pass(pass <> ".", hashed_pass)
end

If you agree that it's an issue, I propose changing both hash_pwd_salt/2 and verify_pass/2 to ensure length <= 72 bytes.

I can prepare a PR as well, but wanted to check first.

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

No branches or pull requests

1 participant