Every security invariant in this Worker is enforced at one correct choke point, and every one of them has at some point been quietly bypassed by the next thing added next to it. All of the following shipped looking right and were found by accident:
The pattern is always the same: a correct mechanism exists, and the seventeenth call site does not go through it. A reviewer cannot catch that by eye.
What to build
Guard tests in the shape this repo already uses — instance-config.test.ts ("no source file issues UPDATE agent_instances SET config = ?"), lib/import-graph.ts + its tests, scripts/check-*.mjs, store/console/src/lib/control-labels.ts. Walk the tree, fail with the offender list and the reason, and prefer a ratcheting budget over a hardcoded allowlist.
Invariants to guard (verify each is actually true before asserting it):
- Every authenticated route resolves identity through
requireUser/requireAdmin — nothing verifies a session inline without applying the suspension gate.
- Every outbound fetch to a user-supplied host goes through
safeFetch, with no bypass path, including test/probe endpoints.
- Every mutating registry tool passes the consent gate before the network or the vault is touched.
- Stored credentials go through the envelope helpers in
lib/crypto.ts — no second scheme, no plaintext column.
- Untrusted remote content is fenced via
lib/untrusted-fence.ts, and the fence neutralizes its own closing marker.
- Destructiveness is judged on the tool name WE send, never a server-supplied
destructiveHint.
Each guard must be verified to go red when the invariant is broken.
Every security invariant in this Worker is enforced at one correct choke point, and every one of them has at some point been quietly bypassed by the next thing added next to it. All of the following shipped looking right and were found by accident:
requireUser. It had three holes —GET /v1/auth/me, the WS chat upgrade (a spend path), and the MCP repo/scaffold tools, which call GitHub with the worker's own token and never reach the API at all.The pattern is always the same: a correct mechanism exists, and the seventeenth call site does not go through it. A reviewer cannot catch that by eye.
What to build
Guard tests in the shape this repo already uses —
instance-config.test.ts("no source file issuesUPDATE agent_instances SET config = ?"),lib/import-graph.ts+ its tests,scripts/check-*.mjs,store/console/src/lib/control-labels.ts. Walk the tree, fail with the offender list and the reason, and prefer a ratcheting budget over a hardcoded allowlist.Invariants to guard (verify each is actually true before asserting it):
requireUser/requireAdmin— nothing verifies a session inline without applying the suspension gate.safeFetch, with no bypass path, including test/probe endpoints.lib/crypto.ts— no second scheme, no plaintext column.lib/untrusted-fence.ts, and the fence neutralizes its own closing marker.destructiveHint.Each guard must be verified to go red when the invariant is broken.