-
Notifications
You must be signed in to change notification settings - Fork 974
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
feat: limit maximum password length #3781
base: master
Are you sure you want to change the base?
feat: limit maximum password length #3781
Conversation
"default": 1024, | ||
"minimum": 20 |
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.
TODO: discuss default values
Should it be limited to max 72 characters to account for bcrypt hasher limitations?
Lines 57 to 65 in 9710549
// Bcrypt truncates the password to the first 72 bytes, following the OpenBSD implementation, | |
// so if password is longer than 72 bytes, function returns an error | |
// See https://en.wikipedia.org/wiki/Bcrypt#User_input | |
if len(password) > 72 { | |
return schema.NewPasswordPolicyViolationError( | |
"#/password", | |
text.NewErrorValidationPasswordMaxLength(72, len(password)), | |
) | |
} |
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.
TODO: update Breaking changes section with new value
ec8570e
to
37810b3
Compare
963e663
to
78a6480
Compare
Hi @aeneasr 👋
I believe my changes are not related to |
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.
From NIST https://pages.nist.gov/800-63-3/sp800-63b.html#a2-length
Users should be encouraged to make their passwords as lengthy as they want, within reason. Since the size of a hashed password is independent of its length, there is no reason not to permit the use of lengthy passwords (or pass phrases) if the user wishes. Extremely long passwords (perhaps megabytes in length) could conceivably require excessive processing time to hash, so it is reasonable to have some limit.
I think the default should be at least 1024, probably even more. The bcrypt hasher already enforces the correct length, so I don't think there is any reason to account for that.
Setting the default to e.g. 2MB also makes it very unlikely that anyone uses a password of this lenght, and basically avoids the breaking change.
Sorry if this sounds dumb but what exactly is the use case for limiting password length? BCrypt will cut off passwords longer than 72 chars (so it does not matter what comes after the 72nd character). |
I totally agree, that we should allow long passwords by default 👍 |
It is a fix for issue discussed in #2449 |
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.
Looks good to me now 👍
The default of 1024 is a breaking change, but I'd guess no-one is really affected by this in the end. It is currently not possible to say how long passwords are, so someone who would upgrade without breaking users would need to collect these data for some time before upgrading (without collecting the passwords obviously).
Another idea to completely avoid a breaking change would be to ignore the limit if it is not set, but as explained I think a default is fine.
Legitimate users could use any length, so long as the client-side could pre-hash the secret it provides to the backend: As for bcrypt with the 72 bytes limit, you can still have what looks like a short password, 1024 bytes is plenty as a limit in that sense 👍 Putting a service like Caddy in front to limit abuse (which the pre-hash approach wouldn't help with obviously) is also fairly simple to configure.
They could just contact an admin or perform a password reset? At that length it's only likely to affect someone who misunderstands security in the first place.
It's possible to attack depending on context. Length does not equate to secure. Entropy calculated based on Kerckhoff's Principle does establish actual security strength though.
With pre-hashing you can pretty much have a fixed length compressed to 64 chars or less, regardless of input length. That's still more bits than you'd get from the bcrypt hash. Collisions for SHA-256 start to occur around 128-bit IIRC, which isn't all that feasible considering the amount of energy that'd require to. Additional info (password length vs entropy)A password like Kerckhoffs's Principle is what should be considered for security strength, not length. Assume the attacker knows the minimum entropy of your password generation method. In the prior example that could be to repeat the 3 family emoji followed by a specific emoji for a distinct password. If targeting specifically 4 random emoji from Unicode 13.1 (
The real entropy of the above pattern shown however is very low (as opposed to that passphrase), although it may not be as easily guessed via typical brute-force patterns (unlikely even tried for emoji... but this is not an endorsement, avoid using emoji as passwords, there are numerous caveats that you could run into with compatibility). All this to say that length shouldn't be a big concern. Passphrases are great when done right, and those are very unlikely to reach such lengths. Anyone using excessive lengths isn't taking the right approach as the actual entropy is what matters, while the final hash output itself is where any additional entropy of a password is wasted. For reference, roughly 114-bits of entropy IIRC is sufficient to require enough energy to boil all the oceans on earth. If an attacker wants your data that badly they'll find a more affordable / realistic alternative to gain access. Encourage adoption of password generators and users don't have to worry much at all :) |
Does this affect only argon2? I checked the code and BCrypt does limit the password length to 72 characters: Line 60 in 7674f46
We really don't recommend using argon2 any more because it is too complex to tune correctly. |
What makes you think that? No one mentioned that here. Some want to see a byte limit to prevent malicious payloads. 72 bytes would not fit the 4 emoji sequence I shared though.
It's not that complex IIRC? You have two tunables for memory and cpu resources instead of just cpu. In both cases you adjust the those for interactive login time (eg 250ms). You want argon2id with a reasonably amount of memory difficulty to reduce parallelism for an attacker. Presently GPUs last I knew still don't have enough local memory per core to properly accel bcrypt, so FPGA is more affordable hardware choice for attacking bcrypt. Memory is expensive, argon2id shines at that. |
I don‘t understand to be honest. There is a hard limit in our BCrypt implementation that limits the maximum length to 72 characters. So why do we need another configuration that limits it to some number when the implementation in any case errors for anything larger than 72? This limit does not exist with Argon2id iirc, hence my assumption. |
Ok I just checked to find Kratos only has support for
The concern that users above were raising about length AFAIK wasn't specific to an implementation like bcrypt with 72 bytes. It was the request itself could be provided with an absurd payload, say the password is sent with a size 2x or more than the servers available memory.... does your bcrypt 72 bytes check run prior to the server receiving that payload? When the server receives a request with an excessive input, it's buffering that all into memory until it finishes receiving the request body, only then would your length check be run right? However if there isn't enough memory in the first place, Kratos or something else is likely to OOM yeah? I haven't tried to verify if this affects Kratos. Just clarifying the earlier concern expressed. I'm not familiar with Go or Kratos, so I can't really review the PR. At a glance I don't see anything that actually addresses the OOM / DDoS attack concern, other than attempts to restrict the input length before and after the request itself via frontend and backend, but I don't see a limit set on the request body size for the endpoint? This doesn't bother me since a reverse proxy can manage the max body size, but you need to know to do that since Kratos is not actively preventing it? (you also advised handling this via a reverse proxy in 2022) For reference |
Allow to specify max password length. See #2449
Related issue(s)
This change resolve issue mentioned in #2449
Go one step closer to ideal solution mentioned in #2396
Checklist
contributing code guidelines.
vulnerability. If this pull request addresses a security vulnerability, I
confirm that I got the approval (please contact
security@ory.sh) from the maintainers to push
the changes.
works.
introduces a new feature.
Further Comments