Repository navigation
fix(auth): consume account rate-limit only after signature verification (CD-04) - #4066
Merged
Merged
Conversation
…on (CD-04) The login route consumed the per-account bucket keyed by the submitted username before the chain lookup and posting-key signature verification, so an attacker with their own valid challenge + CSRF token could submit invalid signatures naming a victim and 429-lock the victim's real logins (targeted login DoS, audit CD-04). The account bucket now runs after the signature verifies: unverified attempts only burn the sender's per-IP bucket, while the account dimension keeps rate-limiting verified logins (session churn from rotating IPs). Residual risk: an attacker can still exhaust their own IP quota and trigger per-attempt RPC work, which is exactly what the IP bucket is for.
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.
Problem (audit finding CD-04, MEDIUM)
POST /api/auth/loginconsumed the per-account rate-limit bucket(
auth:login:acct, 10/min) keyed by the submittedusernamebeforethe chain account lookup, challenge validation, and posting-key signature
verification. Both the IP and account buckets are 10 req / 60 s, so an
attacker with their own valid challenge + CSRF token (both obtainable via
GET /api/auth/challenge) could submit well-formed requests with invalidsignatures naming the victim's username, exhaust the victim's account
bucket, and make the victim's real login attempts fail with 429 — a
targeted login lockout / DoS.
Check order — before
auth:login:ip)getAccountRPCdataJSON parse + field matchCheck order — after
auth:login:ip) — unchanged, still the first checkgetAccountRPCdataJSON parse + field matchDesign decision
Option (a) from the audit guidance: keep the IP check where it is and move
the per-account bucket consumption to after successful signature
verification. The enforced property is: a request that cannot be
attributed to the account holder never consumes that account's quota.
Once the posting-key signature verifies, the request is attributable, so
consuming the account bucket there is sound.
Why not a composite (IP, username) failure bucket (option b): forging a
signature is cryptographically infeasible, so per-account damping of
unverified attempts buys nothing the per-IP bucket does not already
provide; option (a) keeps a single account bucket and a smaller diff. The
account dimension still serves its purpose for attributable traffic — it
stops one verified credential being hammered (session churn) from
rotating IPs.
RATE_LIMITS.authLoginAccount(keyauth:login:acct,10/min) is unchanged; only the point of consumption moved.
Residual risks (documented in code + docs):
force a per-attempt
getAccountRPC for well-formed CSRF-valid requests —that is exactly what the IP bucket exists to cap.
bucket (pre-existing fixed-window property, unchanged).
Test evidence
__tests__/api/auth/login.test.ts(27 tests, all passing) — new describeblock "account-bucket attribution (audit CD-04)" with an in-memory
fixed-window counting limiter standing in for the Redis Lua script:
requests naming the victim across 3 rotating IPs → all 401, the victim's
account bucket is never incremented, and the victim's subsequent valid
login from her own IP returns 200 (account bucket count == 1).
rotating IPs succeed; the 11th is denied 429 +
Retry-After: 60andmints no session.
(400), missing CSRF header (403), challenge mismatch (400), unknown
account (404), non-posting key (401), invalid signature (401) — zero
account-bucket increments.
Retry-Aftertest when the IP bucket denies.
verifySignature(viainvocationCallOrder).Full suite:
pnpm test→ 85 files / 1066 tests passed.pnpm lint→no new warnings or errors (pre-existing baseline: 7 warnings + 1
pre-existing error in
__tests__/proxy.test.ts:383, untouched).Docs
docs/CONFIGURATION.mdrate-limit table now reads "IP (all attempts) andaccount (verified logins only)" plus a paragraph explaining the
attribution rule and residual risk;
lib/cache/rate-limit.tsregistrycomments updated to match.