Skip to content

[5/15] Add exponential backoff to auth attempt rate limiting - #158

Open
UnknownJoe796 wants to merge 2 commits into
version-5.3from
v53/auth-backoff
Open

[5/15] Add exponential backoff to auth attempt rate limiting#158
UnknownJoe796 wants to merge 2 commits into
version-5.3from
v53/auth-backoff

Conversation

@UnknownJoe796

Copy link
Copy Markdown
Contributor

Replaces the flat rate-limit window on auth attempts with exponential backoff.


if (ct >= count) {
val block = blocked.coerceAtLeast(expires)
val baseBlock = blocked.coerceAtLeast(expires)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code feels very awkward

UnknownJoe796 and others added 2 commits July 29, 2026 17:01
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
UnknownJoe796 changed the base branch from v53/oauth-pkce to version-5.3 July 30, 2026 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant