Skip to content

Turn the security invariants into guard tests that fail when a new route, tool, or connector forgets them #306

Description

@serge-ivo

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):

  1. Every authenticated route resolves identity through requireUser/requireAdmin — nothing verifies a session inline without applying the suspension gate.
  2. Every outbound fetch to a user-supplied host goes through safeFetch, with no bypass path, including test/probe endpoints.
  3. Every mutating registry tool passes the consent gate before the network or the vault is touched.
  4. Stored credentials go through the envelope helpers in lib/crypto.ts — no second scheme, no plaintext column.
  5. Untrusted remote content is fenced via lib/untrusted-fence.ts, and the fence neutralizes its own closing marker.
  6. 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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendBackend / Worker / API worksecuritySecurity hardening / audit finding

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions