[5/15] Add exponential backoff to auth attempt rate limiting - #158
Open
UnknownJoe796 wants to merge 2 commits into
Open
[5/15] Add exponential backoff to auth attempt rate limiting#158UnknownJoe796 wants to merge 2 commits into
UnknownJoe796 wants to merge 2 commits into
Conversation
UnknownJoe796
commented
Jul 29, 2026
|
|
||
| if (ct >= count) { | ||
| val block = blocked.coerceAtLeast(expires) | ||
| val baseBlock = blocked.coerceAtLeast(expires) |
Contributor
Author
There was a problem hiding this comment.
This code feels very awkward
UnknownJoe796
force-pushed
the
v53/oauth-pkce
branch
from
July 29, 2026 22:54
84236a8 to
e55ee55
Compare
UnknownJoe796
force-pushed
the
v53/auth-backoff
branch
from
July 29, 2026 22:54
923566f to
5af890d
Compare
constrainAttemptRate was a flat counter+block window: once a block lapsed, the counter TTL expired and an attacker got a fresh full batch of attempts (slow "popcorn" brute force). Now each time the limit is hit the block doubles (blocked * 2^level) up to a maxBlocked cap (default 3h), and the strike level is persisted under "$cacheKey-level" with a memory far longer than any single block window. A successful action clears both the counter and the level, so legitimate users are never penalized. First-offense behavior (level 0) is identical to before, and the exponent is capped so the Duration math can't overflow. Follow-ups noted for later: password/TOTP/backup-code limiters key off un-normalized input (case/whitespace can dodge the limit), and per-IP limiting needs sourceIp plumbed into typed handler implementations. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> (cherry picked from commit ef55541) (cherry picked from commit e193629)
Three names (blocked / baseBlock / block) referred to the same block duration as it moved through the function, and the invariant that the block window must be >= the attempt window was duplicated, unexplained, in two branches. Names the concepts once (baseBlockDuration, attemptsSoFar, strikeLevel, maxBlockDuration, blockDuration) and splits the escalation/cap expression into two commented steps. No behavior change. (cherry picked from commit 5af890d)
UnknownJoe796
force-pushed
the
v53/oauth-pkce
branch
from
July 30, 2026 02:19
e55ee55 to
7e99887
Compare
UnknownJoe796
force-pushed
the
v53/auth-backoff
branch
from
July 30, 2026 02:19
5af890d to
2f0e750
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.
Replaces the flat rate-limit window on auth attempts with exponential backoff.