fix(core): case-fold the username before consulting the ceremony rate limiter - #148
Merged
Conversation
wolpert
force-pushed
the
fix/rate-limit-username-case
branch
from
August 5, 2026 15:12
0d03c6e to
97c32d4
Compare
wolpert
enabled auto-merge (rebase)
August 5, 2026 15:19
… limiter UserLookup implementations resolve usernames case-insensitively — DynamoDbUserLookup lower-cases the identity key — but rateLimitedBucket passed the raw request string to CeremonyRateLimiter.tryAcquireForUsername. So "alice", "Alice", and "ALICE" drew on three independent per-username budgets against one account; an 8-character username yields 256 of them, turning a 10/min allowance into ~2560/min. The per-IP bucket does not compensate. It caps a single source at 30/min, but the per-username bucket exists precisely for the distributed case — many sources, one victim — and that is the case the split defeated. Folded at the call site rather than inside InMemoryCeremonyRateLimiter so every implementation inherits the fix, including a host's shared Redis limiter, which had the same bug and no way to know it. The SPI now documents that the argument arrives folded and must be used as given. Case-folding is the safe direction even where a backend is still case-sensitive: the worst case is two genuinely distinct accounts sharing one throttle bucket, which is stricter, not weaker. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
wolpert
force-pushed
the
fix/rate-limit-username-case
branch
from
August 5, 2026 15:21
97c32d4 to
fe056cc
Compare
|
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.



Closes finding 3 of the full-project security audit.
The problem
UserLookupimplementations resolve usernames case-insensitively —DynamoDbUserLookuplower-cases the identity key — butrateLimitedBucketpassed the raw request string toCeremonyRateLimiter.tryAcquireForUsername:So
alice,Alice, andALICEdrew on three independent per-username budgets against one account. An 8-character username yields 256 of them, turning the 10/min allowance into roughly 2560/min.The per-IP bucket does not compensate. It caps a single source at 30/min, but the per-username bucket exists precisely for the distributed case — many sources, one victim — and that is exactly the case the split defeated.
The fix
Case-fold (
toLowerCase(Locale.ROOT)) at the call site, not insideInMemoryCeremonyRateLimiter. That way every implementation inherits the fix — including a host's shared Redis limiter, which had the same bug and no way to know it. The SPI now documents that the argument arrives folded and must be used as given rather than re-derived from a differently-cased source.Why folding is safe even on a case-sensitive backend
Worst case, two genuinely distinct accounts share one throttle bucket — stricter, not weaker. (#5 in this series makes the JDBI backend case-insensitive too, at which point the question is moot.)
Testing
usernameBucketKeyIsCaseFoldedSoVariantsShareOneBudget()drivesAlice/ALICE/aLiCethrough both start ceremonies and asserts all three land on the single keyalice../gradlew :pk-auth-core:checkpasses.🤖 Generated with Claude Code