Skip to content

fix(auth): stop counting credential-less requests as failed logins - #838

Draft
kkalisz wants to merge 1 commit into
Ark0N:masterfrom
kkalisz:fix/auth-429-lockout
Draft

kkalisz wants to merge 1 commit into
Ark0N:masterfrom
kkalisz:fix/auth-429-lockout

Conversation

@kkalisz

@kkalisz kkalisz commented Nov 18, 2026

Copy link
Copy Markdown

Problem

After a server restart, a browser that had Codeman open gets stuck on Too Many Requests — try again later and reloading doesn't help.

  1. Cookie sessions live in memory, so a restart invalidates every cookie.
  2. The open tab's background requests (polling, reconnects) carry only the dead cookie and no Authorization header. Each was counted as a failed login against the client IP.
  3. Ten of them fill the single-user bucket (AUTH_FAILURE_MAX) within seconds.
  4. From then on every request gets a 429 with no WWW-Authenticate challenge, so the browser never shows its login dialog again. The user can't type the (still accepted) correct password until the 15-minute window expires.

Behind a tunnel all traffic arrives as 127.0.0.1, so one stale tab locks out every device. Multi-user mode has the same shape: credential-less requests filled the per-IP pre-gate (AUTH_IP_FAILURE_MAX), which refuses even a correct password once full.

Fix

A request with no Authorization header is not a guess and runs no password check. It now gets a plain 401 + WWW-Authenticate challenge and is not counted, in both modes and even while the IP is rate-limited. That keeps the browser's login dialog reachable.

Unchanged: wrong credentials and malformed Authorization headers are counted and limited exactly as before (same buckets, same caps, same 429 + Retry-After). The hook-secret bucket is untouched.

Security: nothing is gained by sending header-less requests. They cost no scrypt and reveal nothing beyond the existing 401.

Tests

  • auth-security.test.ts: cookie-only requests (3× the cap) stay 401 with a challenge and leave the wrong-password bucket empty. During a lockout a header-less request still gets the 401 challenge, while wrong credentials still get 429.
  • multiuser-auth.test.ts: cookie-only requests past AUTH_IP_FAILURE_MAX stay 401, the per-IP bucket stays empty, and the correct password logs in.
  • All three new tests fail on master without the fix. The six auth suites pass with it (160 tests). Typecheck, lint and prettier are clean.

🤖 Generated with Claude Code

After a server restart every cookie session is gone (they live in memory).
An open tab's background requests then carry only the dead cookie and no
Authorization header. Each one was counted as a failed login: ten filled
the single-user per-IP bucket within seconds, and the 429 that followed
carries no WWW-Authenticate challenge, so the browser never showed its
login dialog again and reloading could not recover for 15 minutes. Behind
a tunnel all clients share 127.0.0.1, so every device was locked out.
Multi-user mode had the same shape against its per-IP pre-gate, which
refuses even a correct password once full.

A request with no Authorization header is not a guess and runs no
password check, so it is now challenged with a plain 401 and not counted,
in both modes and even while the IP is limited. Wrong and malformed
credentials are counted and limited exactly as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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