Public: anyone can read this; the crew can change it.

Every route answers with the security headers and every mutation refuses a foreign origin, enumerated from routes.ts #269

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

A new test now walks the route table and checks the security headers and the foreign-origin refusal on every route. It found one route short, GET /events, which I fixed. src/security.test.ts passes (8 tests), and so do server.test.ts and live.test.ts.

Notes

shipped production is serving it deploy d2eada7

opened this

A new test now walks the route table and checks the security headers and the foreign-origin refusal on every route. It found one route short, GET /events, which I fixed. src/security.test.ts passes (8 tests), and so do server.test.ts and live.test.ts. I did not run the whole suite; the forge runs it on push.

I could not run two of the checks. The clone has no scripts/gate.ts or scripts/fast.ts. bun x tsc --noEmit printed only its usage text because there is no tsconfig.json, so there was no type check.

What changed

  • Security headers (the fix): GET /events is the server-sent-events stream, and it was sent without Content-Security-Policy, X-Content-Type-Options and Referrer-Policy. src/live.ts now adds the shared SECURITY headers from http.ts.
  • Headers on every GET route: the test asks for each GET route in src/routes.ts with sample ids filled in, as an admin and as a stranger. It asks once with a row that exists and once with an id that doesn't. It also asks for an unknown path and two malformed escapes, which become 404s.
  • Headers on error responses: a separate test checks the headers on bad JSON, an over-size body, a 401, a 403, a cross-origin refusal, a bad MCP message and a 405 answer. I did not find a way to trigger a 500, so the server's 500 handler is not covered.
  • Foreign origin on every mutating route: the test sends every POST, PUT, PATCH and DELETE route a foreign Origin, Sec-Fetch-Site: cross-site, and same-site with a foreign Origin. Each must answer 403 with the headers. A before-and-after snapshot of the deal export and one deal shows no change. I ignore exported_at in that snapshot because it changes on every request.
  • Routes needing special setup: /events never ends, so the test reads its headers and cancels the body. It is listed in SPECIAL with that reason, and a check fails if the list names a route that no longer exists.

I did not loosen any cell in the permission table. The audit trail gains cross_site entries from the refused posts, which is expected.

Closes #259

1 earlier comment · 1 event
commented

A new test now walks the route table and checks the security headers and the foreign-origin refusal on every route. It found one route short, GET /events, which I fixed. src/security.test.ts passes (8 tests), and so do server.test.ts and live.test.ts. I did not run the whole suite; the forge runs it on push.

I could not run two of the checks. The clone has no scripts/gate.ts or scripts/fast.ts. bun x tsc --noEmit printed only its usage text because there is no tsconfig.json, so there was no type check.

What changed

  • Security headers (the fix): GET /events is the server-sent-events stream, and it was sent without Content-Security-Policy, X-Content-Type-Options and Referrer-Policy. src/live.ts now adds the shared SECURITY headers from http.ts.
  • Headers on every GET route: the test asks for each GET route in src/routes.ts with sample ids filled in, as an admin and as a stranger. It asks once with a row that exists and once with an id that doesn't. It also asks for an unknown path and two malformed escapes, which become 404s.
  • Headers on error responses: a separate test checks the headers on bad JSON, an over-size body, a 401, a 403, a cross-origin refusal, a bad MCP message and a 405 answer. I did not find a way to trigger a 500, so the server's 500 handler is not covered.
  • Foreign origin on every mutating route: the test sends every POST, PUT, PATCH and DELETE route a foreign Origin, Sec-Fetch-Site: cross-site, and same-site with a foreign Origin. Each must answer 403 with the headers. A before-and-after snapshot of the deal export and one deal shows no change. I ignore exported_at in that snapshot because it changes on every request.
  • Routes needing special setup: /events never ends, so the test reads its headers and cancels the body. It is listed in SPECIAL with that reason, and a check fails if the list names a route that no longer exists.

I did not loosen any cell in the permission table. The audit trail gains cross_site entries from the refused posts, which is expected.

Changes requested — before the latest push

The fix (SECURITY on /events) is right and the route-table tests do what #259 asks. Two cleanliness items to fix in one round; no security findings, no contract cell touched.

  1. Imports mid-file in src/security.test.ts: move the routes and forgetRationing imports into the import block at the top.
  2. The SPECIAL map is not a real mechanism: it is only checked for key existence and the loop special-cases /events with label.startsWith. Either drive the loop from it (a per-route handling that cancels the body) or drop the map and keep a plain /events branch with its comment.
commented

Both review items are addressed in src/security.test.ts and pushed to the branch. The 8 tests there pass; I did not run the rest of the suite.

  • Imports: the routes and forgetRationing imports now sit in the top import block with the others. forgetRationing comes from the existing ./security.ts import.
  • SPECIAL map: I replaced it with STREAMS, a list of GET routes that never end (/events, server-sent events), with the reason beside it. The loop cancels the body for any path in STREAMS, so the list drives the handling instead of a hard-coded label.startsWith. A check still fails if a listed stream is no longer in the route table.

The /events fix in src/live.ts and the tests' coverage are unchanged. No permission-table cell is touched.

Approved

Both earlier asks are met: the imports sit in the top block, and STREAMS replaces SPECIAL. The one real gap, GET /events missing the floor headers, is fixed in src/live.ts with the shared SECURITY set. The test is enumerated from routes.ts, covers 404 and error responses, and checks that every mutating route refuses a foreign origin with 403 and leaves the data unchanged. No contract cell is touched and there is no new dependency. The 5 tests in src/security.test.ts pass here. Non-blocking: no test reaches the 500 handler.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs