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

opened this in answer to

Parked 45d 0h ago

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.

Notes

opened this

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 with Retry-After: 1 and 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_forge now governs only the first-admin claim, and it is relabelled on /admin/limits to say so.
  • M6 – no secrets in idempotency storage (withoutShownOnce in src/http/server.ts): fields named token, secret, link (invite links) or claimUrl are 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/sessions refuses 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 /\host and \\host, which browsers read as //host; that wasn't in the issue.
  • M2 – anonymous spawns: anonymous spawns are now recorded in a new anon_spawn table (migration 20261019180000), 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, resetAnonSpawns now takes the forge's database. The test passes app.db and drops a reset that ran before the app existed, which a fresh data directory makes unnecessary.
  • The header comment in test/signin-throttle.test.ts no longer mentions the forge-wide 200; its assertions are unchanged.
  • I updated docs/THREATS.md to 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

Closes #2922

4 earlier comments
commented

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 with Retry-After: 1 and 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_forge now governs only the first-admin claim, and it is relabelled on /admin/limits to say so.
  • M6 – no secrets in idempotency storage (withoutShownOnce in src/http/server.ts): fields named token, secret, link (invite links) or claimUrl are 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/sessions refuses 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 /\host and \\host, which browsers read as //host; that wasn't in the issue.
  • M2 – anonymous spawns: anonymous spawns are now recorded in a new anon_spawn table (migration 20261019180000), 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, resetAnonSpawns now takes the forge's database. The test passes app.db and drops a reset that ran before the app existed, which a fresh data directory makes unnecessary.
  • The header comment in test/signin-throttle.test.ts no longer mentions the forge-wide 200; its assertions are unchanged.
  • I updated docs/THREATS.md to 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

commented

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/sessions refuses a cross-origin request before it sets a cookie.
  • L3: Markdown links containing a control byte, or a //host disguised 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_forge from this branch and api.anonymous_per_source from main.
  • src/spawn/door.ts: keeps this branch's reserve-then-release in place of main's checkAnonSpawn, and keeps main's startedAt and startWatch liveness 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

commented

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/sessions refuses a cross-origin request before it sets a cookie.
  • L3: Markdown links containing a control byte, or a //host disguised with backslashes, are refused.

The latest main is merged in:

  • src/settings/limits.ts: keeps both new limits, spawn.anon_per_forge from this branch and api.anonymous_per_source from main.
  • src/spawn/door.ts: keeps this branch's reserve-then-release in place of main's checkAnonSpawn, and keeps main's startedAt and startWatch liveness watch for each new child.

The last check failed on two tests:

  • test/threats-doc.test.ts: the sign-in line in docs/THREATS.md named two test files, and the doc's rule is one per protection. The doc was wrong, not the test: the line now names only test/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

commented

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/sessions refuses a cross-origin request before it sets a cookie.
  • L3: Markdown links containing a control byte, or a //host disguised with backslashes, are refused.

The latest main is merged in:

  • src/settings/limits.ts: keeps both new limits, spawn.anon_per_forge from this branch and api.anonymous_per_source from main.
  • src/spawn/door.ts: keeps this branch's reserve-then-release in place of main's checkAnonSpawn, and keeps main's startedAt and startWatch liveness 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 real passwordHashes gate, then makes three sign-in attempts that each come back throttled with retryAfter: 1. Afterwards the account at that source still gets all three of its signin.per_account attempts. This test needs admission.giveBack() on busy in src/core/users.ts.
  • Spent source window (same file): a source runs out of its signin.per_source budget, and its refused attempts at sam cost nothing. Once the source limit is raised, sam from that source still has every attempt. This test needs limiter.refund(accountKey) in src/core/signin-window.ts.
  • Spawns that make nothing (test/spawn-anon.test.ts): goes through POST /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 in src/spawn/door.ts.
    • The test calls setStrangerLimits(app, {}) first. The earlier tests in that file already use up main's limit of 10 stranger plans a minute.
  • SHOWN_ONCE comment in src/http/server.ts: matching fields by name means a public link comes 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

commented

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

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs