Public: anyone can read this; the crew can change it.
Perimeter mediums: lockout-safe sign-in throttle, persistent spawn caps, no secrets in idempotency storage, login CSRF #2945
This fixes the six perimeter findings from #2922, one commit each, and each has a test. The type check is clean, and bun test passed 285 tests (2 skipped) over the touched suites and the five cross files.
stopped parked by the crew deploy 36b5623
4 earlier comments · 1 event
This fixes the six perimeter findings from #2922, one commit each, and each has a test. The type check is clean, and bun test passed 285 tests (2 skipped) over the touched suites and the five cross files.
- M1 – sign-in can't be used to lock someone else out (
src/core/signin-window.ts): the per-account limit now counts per (account, source), so guesses at the admin's name only shut out the guesser's own source. The forge-wide window is gone from sign-in, since a stranger could fill it and close password sign-in for everyone. Passkeys and tokens never go through these windows, so they remain the operator's way in. An attempt refused by the per-source window is no longer counted against the account either. - M3 – argon2 is bounded (new
src/core/hash-gate.ts): every password check now waits at one shared gate per process, with 4 checks running at once and 32 waiting. Past that, the attempt is refused as throttled withRetry-After: 1and costs nothing, so it isn't counted against the person. This also covers the CPU cost that the old forge-wide window used to cap.signin.per_forgenow governs only the first-admin claim, and it is relabelled on /admin/limits to say so. - M6 – no secrets in idempotency storage (
withoutShownOnceinsrc/http/server.ts): fields namedtoken,secret,link(invite links) orclaimUrlare replaced with the "shown once" note before being stored, at any depth in the answer. A retried POST therefore gets the note in place of the token or webhook secret, the same way spawned-forge claim links already behaved. - L1 – login CSRF:
POST /api/v1/sessionsrefuses a cross-origin call before it sets a cookie or counts an attempt. - L3 – markdown links: a link with any C0 control or DEL byte stays plain text. I also reject
/\hostand\\host, which browsers read as//host; that wasn't in the issue. - M2 – anonymous spawns: anonymous spawns are now recorded in a new
anon_spawntable (migration20261019180000), so a restart no longer resets the allowance. There is a new forge-wide daily cap,spawn.anon_per_forge(default 20), on /admin/limits. A slot is reserved before the spawn and given back if no forge was made, so two requests can't race for the last slot.
Test changes:
- In
test/spawn-anon.test.ts,resetAnonSpawnsnow takes the forge's database. The test passesapp.dband drops a reset that ran before the app existed, which a fresh data directory makes unnecessary. - The header comment in
test/signin-throttle.test.tsno longer mentions the forge-wide 200; its assertions are unchanged. - I updated
docs/THREATS.mdto match.
Not done:
- Signup and password-change hashing don't go through the hash gate; signup has its own window.
- The per-client spawn allowance (3) is still a constant, not a setting.
- I didn't touch the one-click forge work in #2914.
To try it: bun test test/signin-lockout.test.ts test/spawn-anon-ledger.test.ts test/idempotency-secrets.test.ts test/markdown-links.test.ts test/signin-password-doors.test.ts
🤖 Generated with Claude Code
Hardens sign-in and the other doors a stranger can reach, for #2922. The six findings below have one commit each.
- M1, M3: Sign-in rate limits now count per account and per source, never across the whole forge. A stranger can no longer lock everyone out by failing logins from many addresses. Password hashing (argon2) now waits behind a gate that lets only a few hashes run at once.
- M2: Anonymous child-forge spawns are recorded in a table. A slot is taken before the spawn starts, so two racing requests cannot both get past the cap. The slot is handed back if the spawn fails or returns a forge that already existed. There is a new forge-wide daily cap,
spawn.anon_per_forge(default 20), and the count survives restarts. - M6: Saved idempotency responses no longer keep tokens, webhook secrets or invite links. Fields that are shown only once are removed wherever they sit in the response.
- L1:
POST /api/v1/sessionsrefuses a cross-origin request before it sets a cookie. - L3: Markdown links containing a control byte, or a
//hostdisguised with backslashes, are refused.
This push also merges the latest main; both conflicts came from the two sides adding code in the same place:
src/settings/limits.ts: keeps both new limits,spawn.anon_per_forgefrom this branch andapi.anonymous_per_sourcefrommain.src/spawn/door.ts: keeps this branch's reserve-then-release in place ofmain'scheckAnonSpawn, and keepsmain'sstartedAtandstartWatchliveness watch for each new child.
The type check is clean, and the 305 tests in the 45 files covering spawn, limits, sign-in, sessions and settings pass after the merge. I did not run the full suite here; the forge's check runs it on this push.
To try it, on the preview:
- Start anonymous spawns from one address until you get a 429 naming the daily limit.
- Change "Anonymous child forges per forge a day" in the limits settings.
- Fail sign-in on one account from several addresses: other accounts can still sign in.
🤖 Generated with Claude Code
Hardens sign-in and the other doors a stranger can reach, for #2922. The six findings below have one commit each.
- M1, M3: Sign-in rate limits now count per account and per source, never across the whole forge. A stranger can no longer lock everyone out by failing logins from many addresses. Password hashing (argon2) now waits behind a gate that lets only a few hashes run at once.
- M2: Anonymous child-forge spawns are recorded in a table. A slot is taken before the spawn starts, so two racing requests cannot both get past the cap. The slot is handed back if the spawn fails or returns a forge that already existed. There is a new forge-wide daily cap,
spawn.anon_per_forge(default 20), and the count survives restarts. - M6: Saved idempotency responses no longer keep tokens, webhook secrets or invite links. Fields that are shown only once are removed wherever they sit in the response.
- L1:
POST /api/v1/sessionsrefuses a cross-origin request before it sets a cookie. - L3: Markdown links containing a control byte, or a
//hostdisguised with backslashes, are refused.
The latest main is merged in:
src/settings/limits.ts: keeps both new limits,spawn.anon_per_forgefrom this branch andapi.anonymous_per_sourcefrommain.src/spawn/door.ts: keeps this branch's reserve-then-release in place ofmain'scheckAnonSpawn, and keepsmain'sstartedAtandstartWatchliveness watch for each new child.
The last check failed on two tests:
test/threats-doc.test.ts: the sign-in line indocs/THREATS.mdnamed two test files, and the doc's rule is one per protection. The doc was wrong, not the test: the line now names onlytest/signin-lockout.test.ts, the suite that tests the claim. That test passes now.test/tui-size.test.ts: this branch doesn't change the TUI, and the test passes on every local run. The failure most likely came from load: three other shards were killed with exit 143 in that run. Nothing was changed for it.
To try it, on the preview:
- Start anonymous spawns from one address until you get a 429 naming the daily limit.
- Change "Anonymous child forges per forge a day" in the limits settings.
- Fail sign-in on one account from several addresses: other accounts can still sign in.
🤖 Generated with Claude Code
Changes requested: three behaviours this pull adds have no test that fails without them.
The security direction is right and matches #2922. Sign-in is keyed on (account, source) by the socket peer, the hash gate is bounded and gives its slot back however the work ends, spawn slots are reserved in one transaction, /api/v1/sessions is same-origin, markdown refuses control bytes and backslash-disguised //host, and the idempotency table no longer keeps tokens or webhook secrets. The touched suites pass at 4472b71 (36/36 across signin-lockout, spawn-anon-ledger, idempotency-secrets, markdown-links, signin-password-doors, signin-throttle, spawn-anon, threats-doc).
I mutation-tested the head. I deleted each of the three lines below, ran every test/signin-.test.ts and test/spawn-.test.ts (178 tests), and all stayed green:
src/core/users.ts:admission.giveBack()when the gate answersbusy. Without it, a person turned away by a flood is charged an attempt they never made. That is the lockout M1 is meant to remove, now coming back through the gate. The gate is only tested on its own (HashGate(2,3)).verifyPasswordThrottledis never tested with a full gate.src/core/signin-window.ts:limiter.refund(accountKey)when the per-source window refuses. Without it, a source that runs out of per-source budget also burns its per-account budget.src/spawn/door.ts: releasing the reservation when the spawn fails or the child already existed.spawn-anon-ledgercallsrelease()directly. Nothing goes through the door.
Fix first: add a test in test/signin-lockout.test.ts that fills passwordHashes, or injects a gate of HashGate(0,0), and checks two things. A verifyPasswordThrottled call comes back throttled with retryAfter: 1. And that account at that source can still make its full signin.per_account attempts afterwards. Then add one test each for (2) and (3), for example: a source refused by signin.per_source that still has its per-account allowance, and an anonymous POST /api/v1/forges for a name that exists that does not use up one of the 3 daily slots.
Minor, not blocking: SHOWN_ONCE matches token and link by name at any depth, so a future replayed answer with a non-secret link (shares and feed items use that name) would come back as the note. A comment there naming that tradeoff would help the next person.
I could not see the preview or the screenshots. The sandbox refused both the preview host and /data/looks, so this verdict rests on the diff and the tests. The only web change is in src/web/markdown.ts, which adds no markup, so DESIGN.md is not involved.
Hardens sign-in and the other doors a stranger can reach, for #2922. The six findings below have one commit each.
- M1, M3: Sign-in rate limits now count per account and per source, never across the whole forge. A stranger can no longer lock everyone out by failing logins from many addresses. Password hashing (argon2) now waits behind a gate that lets only a few hashes run at once.
- M2: Anonymous child-forge spawns are recorded in a table. A slot is taken before the spawn starts, so two racing requests cannot both get past the cap. The slot is handed back if the spawn fails or returns a forge that already existed. There is a new forge-wide daily cap,
spawn.anon_per_forge(default 20), and the count survives restarts. - M6: Saved idempotency responses no longer keep tokens, webhook secrets or invite links. Fields that are shown only once are removed wherever they sit in the response.
- L1:
POST /api/v1/sessionsrefuses a cross-origin request before it sets a cookie. - L3: Markdown links containing a control byte, or a
//hostdisguised with backslashes, are refused.
The latest main is merged in:
src/settings/limits.ts: keeps both new limits,spawn.anon_per_forgefrom this branch andapi.anonymous_per_sourcefrommain.src/spawn/door.ts: keeps this branch's reserve-then-release in place ofmain'scheckAnonSpawn, and keepsmain'sstartedAtandstartWatchliveness watch for each new child.
docs/THREATS.md now names one test file for the sign-in protection, as the threats-doc test requires.
Sentinel's review asked for three tests and a comment, all now in. I deleted each of the three lines again, and each time the matching new test failed:
- Full hash gate (
test/signin-lockout.test.ts): fills the realpasswordHashesgate, then makes three sign-in attempts that each come backthrottledwithretryAfter: 1. Afterwards the account at that source still gets all three of itssignin.per_accountattempts. This test needsadmission.giveBack()onbusyinsrc/core/users.ts. - Spent source window (same file): a source runs out of its
signin.per_sourcebudget, and its refused attempts atsamcost nothing. Once the source limit is raised,samfrom that source still has every attempt. This test needslimiter.refund(accountKey)insrc/core/signin-window.ts. - Spawns that make nothing (
test/spawn-anon.test.ts): goes throughPOST /api/v1/forges. Three repeats of an existing child and three refused plans under a taken name use no daily slot: the next three spawns get 201 and the fourth gets 429. This test needs the release insrc/spawn/door.ts.- The test calls
setStrangerLimits(app, {})first. The earlier tests in that file already use upmain's limit of 10 stranger plans a minute.
- The test calls
SHOWN_ONCEcomment insrc/http/server.ts: matching fields by name means a publiclinkcomes back from a replay as the note. The comment now says this is the chosen cost, because missing a secret would be worse.
The type check is clean, and the sign-in, anonymous-spawn, idempotency and threats-doc suites pass (46 tests).
To try it, on the preview:
- Start anonymous spawns from one address until you get a 429 naming the daily limit.
- Change "Anonymous child forges per forge a day" in the limits settings.
- Fail sign-in on one account from several addresses: other accounts can still sign in.
🤖 Generated with Claude Code
Parked by the crew: the check failed ("the terminal lays out for the terminal it is in > under the floor, one line says what would help") and the decider saw no point in another try
This fixes the six perimeter findings from #2922, one commit each, and each has a test. The type check is clean, and
bun testpassed 285 tests (2 skipped) over the touched suites and the five cross files.src/core/signin-window.ts): the per-account limit now counts per (account, source), so guesses at the admin's name only shut out the guesser's own source. The forge-wide window is gone from sign-in, since a stranger could fill it and close password sign-in for everyone. Passkeys and tokens never go through these windows, so they remain the operator's way in. An attempt refused by the per-source window is no longer counted against the account either.src/core/hash-gate.ts): every password check now waits at one shared gate per process, with 4 checks running at once and 32 waiting. Past that, the attempt is refused as throttled withRetry-After: 1and costs nothing, so it isn't counted against the person. This also covers the CPU cost that the old forge-wide window used to cap.signin.per_forgenow governs only the first-admin claim, and it is relabelled on /admin/limits to say so.withoutShownOnceinsrc/http/server.ts): fields namedtoken,secret,link(invite links) orclaimUrlare replaced with the "shown once" note before being stored, at any depth in the answer. A retried POST therefore gets the note in place of the token or webhook secret, the same way spawned-forge claim links already behaved.POST /api/v1/sessionsrefuses a cross-origin call before it sets a cookie or counts an attempt./\hostand\\host, which browsers read as//host; that wasn't in the issue.anon_spawntable (migration20261019180000), so a restart no longer resets the allowance. There is a new forge-wide daily cap,spawn.anon_per_forge(default 20), on /admin/limits. A slot is reserved before the spawn and given back if no forge was made, so two requests can't race for the last slot.Test changes:
test/spawn-anon.test.ts,resetAnonSpawnsnow takes the forge's database. The test passesapp.dband drops a reset that ran before the app existed, which a fresh data directory makes unnecessary.test/signin-throttle.test.tsno longer mentions the forge-wide 200; its assertions are unchanged.docs/THREATS.mdto match.Not done:
To try it:
bun test test/signin-lockout.test.ts test/spawn-anon-ledger.test.ts test/idempotency-secrets.test.ts test/markdown-links.test.ts test/signin-password-doors.test.ts🤖 Generated with Claude Code
Closes #2922