Rate-limit /login to stop brute-force attacks (GHSA-frch-4w6v-q5xx)
feat(api): rate-limit /login to stop brute-force attacks (GHSA-frch-4w6v-q5xx)
Rate-limit /login to stop brute-force attacks (GHSA-frch-4w6v-q5xx)135bc9-feat-rate-limit-login-to-stop-brute-force-attacks-cve-2026-85734featrate limit login stop brute force
Committed by danielaskdd
commit message
feat(api): rate-limit /login to stop brute-force attacks (GHSA-frch-4w6v-q5xx)
POST /login had no rate limiting, lockout, or backoff (CWE-307): a network
attacker could submit unlimited password guesses at full speed and brute-force
any account.
Add an in-process sliding-window limiter (LoginRateLimiter) keyed by client IP
+ username. After LOGIN_MAX_FAILED_ATTEMPTS failures within
LOGIN_LOCKOUT_WINDOW_SECONDS (defaults 5 / 300s) further attempts get HTTP 429
with Retry-After until the window passes; a successful login clears the key.
Set LOGIN_MAX_FAILED_ATTEMPTS=0 to disable.
The check runs before the bcrypt verification, so a locked key is also rejected
without paying the bcrypt cost (bounds the login-flood CPU/DoS surface). Keying
on IP+username avoids one attacker locking out unrelated accounts behind a
shared proxy IP; X-Forwarded-For is not trusted. State is per-process (uvicorn
forces a single worker; under gunicorn the effective limit is N x the value),
documented in env.example alongside a note to add a proxy/WAF limit for strict
multi-worker enforcement.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>Editor assessment
This commit patches CVE-2026-85734. Strong write-up. The body explains CWE-307, the missing rate limit/lockout on POST /login, and then the design: a sliding-window limiter keyed by IP plus username, 5 failures per 300s, 429 with Retry-After, success clearing the key, the check running before bcrypt, and the honest caveat that state is per-process under gunicorn. That is exactly the context a security change needs. The subject's length and GHSA reference add noise, so it lands at 4 rather than 5. Formally the api scope and feat type are correct and the body is a well-structured explanation; the only blemishes are subject length and the GHSA reference, which are presentation issues rather than substance.