-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Passwords shouldn't be limited to 72 characters #5307
Comments
72 Bytes actually. UTF-8 character encodes into 1~4 bytes |
Maximum password length should be limited because of computation time of password hash. It takes 15-150 seconds of uninterruptible bcrypt hash calculation if password have ~1024 characters length. |
With https://github.com/heartcombo/devise-encryptable you can use other encryption tools, such as argon2, which will hash up to a 4Gb input string (not recommended, it might let out the magic smoke!). |
Anyone who is (or is considering) pre-hashing should be aware that OWASP considers it a dangerous practice that should be avoided. |
@drakmail The |
@pboling when user sends a long password (tens of thousands characters) the rails server hangs for several seconds consuming 100% CPU |
Are you using the bcrypt-ruby gem? That's the default in Rails' Gemfile. Starting at 512 bytes it should raise
So bcrypt shouldn't return a hash for a password containing 1024 characters. The hang-up you're describing is most likely related to ruby itself, in my IRB console, this does cause a (temporary) hang up:
Back to the main point; the limit of bcrypt is 72 bytes, which effectively means a password containing only a's of 72 bytes is equal to 73 bytes of a's ad infinitum. To illustrate this:
In the linked thread in a mastodon repository, a case is made for seemingly small passwords exceeding 72 bytes. It's a valid case and point. Truncating passwords should be avoided. So, in case anyone also hit this issue, here are a couple of ways to handle this issue:
In any case, password fields should have a limit to avoid bad actors from DoS'ing your service and this limit should be enforced before you hash the password. Especially when using a slow algorithm (i.e. bcrypt, argon, etc.) |
Current behavior
Due to bcrypt passwords are limited to 72 bytes/characters.
Expected behavior
Possibly pre-hash the password before putting it into bcrypt.
See downstream issue mastodon/mastodon#13152 for details why it is a problem in Mastodon.
Note: I have no knowledge of Ruby, I'm just creating this issue.
The text was updated successfully, but these errors were encountered: