Public: anyone can read this; the crew can change it.
Repeated wrong passwords for one username are slowed or refused with a 429 and Retry-After: twelve in a row answer 422 each on production #14384
Check · Review · Land · Live done — Landed and live in production.
Wrong passwords at one account from one client address are now counted over ten minutes. After 8, every attempt for that pair, including the right password, gets 429 with an integer Retry-After until the window passes. Why production let twelve through: main already had a sign-in limiter in src/core/signin-window.ts.
shipped production is serving it deploy 4ec2c16
Wrong passwords at one account from one client address are now counted over ten minutes. After 8, every attempt for that pair, including the right password, gets 429 with an integer Retry-After until the window passes.
Why production let twelve through: main already had a sign-in limiter in src/core/signin-window.ts. It allows 20 attempts per account per source a minute, 60 per source and 200 for the whole forge. Twelve wrong guesses never reach 20, so this was a limit set too high, not one hidden by the tunnel's shared address.
What changed
src/core/signin-window.tshas a slower window,FAILURES_PER_ACCOUNT = 8inFAILURES_WINDOW_MS = 10 * 60_000, each with its reason beside it. It is checked before the password hash runs.- It is keyed by account and client address, like the minute window. A stranger fills only their own window, so an owner signing in from somewhere else is never locked out.
- A refused attempt is not counted. A right password clears the count for that account and address.
- Two cases give the attempt back without clearing anything: the hash gate was busy, or the account is still waiting for approval. These now call a new
notJudged()instead ofsucceeded()(src/core/users.ts). - An unknown username is counted exactly like a real one: the same 422 words, then the same 429, so the answers don't reveal which names exist.
- The passkey, claim and parent sign-ins (
signinWindow) count every attempt and can't tell a wrong secret from a right one, so they skip the new window. API tokens are untouched. RateLimiter.forget(key)is new insrc/core/ratelimit.ts.docs/THREATS.mdnames the new window.
Tests: test/signin-failures-window.test.ts checks:
- Through the limiter with set client addresses: a ninth attempt is refused with a wait of 4–5 minutes, while another address and another account still get in. The door reopens once the window passes (simulated clock), and a right password clears the count.
- Over
POST /signin: eight 422s, then 429 withRetry-Afterand "Too many attempts", for the right password too. Thenbobsigns in with a 303. An unknown name gets the same answers, and a success clears the count.
It fails on today's main.
Three existing tests asserted the old count that this issue changes, so I updated them:
signin-throttle: the door now closes after 8 wrong guesses instead of 20.signin-window-limits: passesfailures: falseso it still checks the minute window on its own.perimeter-mediumsM1: loops until whichever window shuts first.
Not done: the page still says "Too many attempts. Try again in N seconds", which can mean several hundred seconds. Rewording it would touch src/web/ and so would also require terminal-screen and docs changes, which this issue doesn't call for. The new numbers are fixed constants as the issue asked, not settings on /admin/limits.
bun x tsc --noEmit and bun scripts/gate.ts --fix pass. So do the sign-in, rate-limit, passkey, perimeter and terminal sign-in test files: about 170 tests, none failing.
To try it on the preview: post a wrong password to /signin nine times with the same username and an Origin header. The ninth answer is 429 with Retry-After, and the right password is refused too until the window passes.
🤖 Generated with Claude Code
After eight wrong passwords at one account from one source, every attempt there answers 429 with Retry-After for ten minutes (#14373). A slow window in src/core/signin-window.ts counts them, and a right password clears it. Unknown usernames are counted the same way. The passkey, claim and parent doors are not held to it.
This push fixes the two suites the window broke. No product code changed in it:
test/signin-failures-window.test.ts: the unknown-username case ran the full-cost decoy argon2 hash eight times and took 2.3 s, over the 2 s per-test budget. Running the attempts in parallel doesn't work because the hash slots refuse them, and the source address is different over TCP and over a unix socket, so the window can't be pre-filled by address. Instead, for that hash only, the test swaps in a cheap verify and checks that it ran eight times. The test now takes 37 ms.test/origins-sync.test.ts: the GitHub provider fetches withx-access-token:<token>, which is GitHub's convention. In this test a forge stands in for GitHub's git host and had no such account. Every fetch counted as a wrong password, which did no harm before because the repo is public and 20 a minute never filled. Under the new window the ninth fetch got 429, so the "refs that moved upstream" sync saw no push. The test was relying on wrong credentials being harmless, so the upstream forge now has anx-access-tokenaccount.
Not changed: a git client with a stale or wrong password, reading a public repo, gets 429 once the window fills. The old minute window already worked that way; it now happens after fewer attempts.
Three other suites in the failed check (stuck-pile, keeper-measures, deadends) fail the same way on the base commit in this sandbox, so this branch didn't cause them. job-alloc, spawn-reach-door and pull-check-again pass here. The sign-in suites and every suite that points the GitHub provider at a real forge (12 files) pass. The gate and tsc --noEmit are clean.
To try it: sign in with a wrong password nine times for one username. The ninth answers 429 with Retry-After, and so does the right password, until ten minutes pass. Another username still signs in.
🤖 Generated with Claude Code
Works on the preview: eight wrong passwords for one unknown username answer 422, the ninth and tenth answer 429 with an integer Retry-After (589, 588). The window is keyed by account and source, refused attempts are not counted, a success clears it, and the passkey/claim/parent doors are exempt. The tests cover the limit, the clear, and the unknown-name case.
Two things I would do next:
- Reword the 429 page for a ten-minute wait ("try again in about 10 minutes"), with the terminal screen, and consider letting git Basic auth on a public repo fall back to anonymous so a stale password does not lock a cloner out for ten minutes.
- Remove the stale comment above the slow-window block in
signin-window.ts("The one key first..."), which now contradicts the line below it. Replace the hard-coded decoy-hash prefix and theBun.password.verifymonkeypatch in the unknown-username test with an injected cheap decoy.
Wrong passwords at one account from one client address are now counted over ten minutes. After 8, every attempt for that pair, including the right password, gets 429 with an integer
Retry-Afteruntil the window passes.Why production let twelve through: main already had a sign-in limiter in
src/core/signin-window.ts. It allows 20 attempts per account per source a minute, 60 per source and 200 for the whole forge. Twelve wrong guesses never reach 20, so this was a limit set too high, not one hidden by the tunnel's shared address.What changed
src/core/signin-window.tshas a slower window,FAILURES_PER_ACCOUNT = 8inFAILURES_WINDOW_MS = 10 * 60_000, each with its reason beside it. It is checked before the password hash runs.notJudged()instead ofsucceeded()(src/core/users.ts).signinWindow) count every attempt and can't tell a wrong secret from a right one, so they skip the new window. API tokens are untouched.RateLimiter.forget(key)is new insrc/core/ratelimit.ts.docs/THREATS.mdnames the new window.Tests:
test/signin-failures-window.test.tschecks:POST /signin: eight 422s, then 429 withRetry-Afterand "Too many attempts", for the right password too. Thenbobsigns in with a 303. An unknown name gets the same answers, and a success clears the count.It fails on today's main.
Three existing tests asserted the old count that this issue changes, so I updated them:
signin-throttle: the door now closes after 8 wrong guesses instead of 20.signin-window-limits: passesfailures: falseso it still checks the minute window on its own.perimeter-mediumsM1: loops until whichever window shuts first.Not done: the page still says "Too many attempts. Try again in N seconds", which can mean several hundred seconds. Rewording it would touch
src/web/and so would also require terminal-screen and docs changes, which this issue doesn't call for. The new numbers are fixed constants as the issue asked, not settings on /admin/limits.bun x tsc --noEmitandbun scripts/gate.ts --fixpass. So do the sign-in, rate-limit, passkey, perimeter and terminal sign-in test files: about 170 tests, none failing.To try it on the preview: post a wrong password to
/signinnine times with the same username and anOriginheader. The ninth answer is 429 withRetry-After, and the right password is refused too until the window passes.🤖 Generated with Claude Code
Closes #14373