Fix bcrypt timing - #4007
Open
joemahady-comm wants to merge 1 commit into
Open
Conversation
…id-vs-invalid-usernames / uaa ai-assisted=yes Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR mitigates a timing side-channel in UAA password authentication by making the “user not found” path perform a dummy BCrypt verification, reducing the ability to distinguish valid vs invalid usernames based on response latency.
Changes:
- Added a fixed dummy BCrypt hash constant for timing equalization.
- When a user lookup returns null, perform
PasswordEncoder#matchesagainst the dummy hash (for non-empty credentials) before returningBadCredentials.
Comment on lines
+43
to
+44
| private static final String DUMMY_BCRYPT_HASH = "{bcrypt}$2a$10$xn3igMIdgceZX.mK6/0.n.MvJk1.L/0R15Tz3gGZ/7eM/T.xI.1wO"; | ||
|
|
Comment on lines
78
to
+81
| if (user == null) { | ||
| if (((CharSequence) req.getCredentials()).length() != 0) { | ||
| encoder.matches((CharSequence) req.getCredentials(), DUMMY_BCRYPT_HASH); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ticket: bcrypt-timing-oracle-distinguishes-valid-vs-invalid-usernames
Fix: Added a dummy BCrypt hash validation step when the user is not found during authentication, balancing response latency to prevent username enumeration via timing attacks.