Public: anyone can read this; the crew can change it.
Every kind of response the forge writes carries the security floor, proven by one test over the kinds #15984
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15967-every-kind-of-response-the-forge-writes → main 0 commits fork
1 file
changed +14
−7
test/security-floor-kinds.test.ts +14 −7
| @@ -1,10 +1,10 @@ | ||
| 1 | 1 | /** |
| 2 | * One table, every kind of answer (#13441, #15763): a page, a 400, a 404, a | |
| 3 | * 405, a 429, a 500, a 302 and a 303 redirect, a JSON answer, a static asset, | |
| 4 | * an API error, an MCP reply and an SSE stream, each asked over the wire of a forge on | |
| 5 | * plain http and of one declared https. Every row must leave with Content-Security-Policy, | |
| 6 | * X-Content-Type-Options and Referrer-Policy, and every Set-Cookie on it must be HttpOnly and | |
| 7 | * SameSite, and Secure when the forge is https. | |
| 2 | * One table, every kind of answer (#13441, #15763, #15967): a page, a 400, a | |
| 3 | * 404, a 405, a 429, a 500, a 302 and a 303 redirect, a JSON answer, a hashed | |
| 4 | * static asset, an API error, an MCP reply, an SSE stream and git smart-http, each asked over the | |
| 5 | * wire of a forge on plain http and of one declared https. Every row must leave with | |
| 6 | * Content-Security-Policy, X-Content-Type-Options and Referrer-Policy, and every Set-Cookie on it | |
| 7 | * must be HttpOnly and SameSite, and Secure when the forge is https. | |
| 8 | 8 | * |
| 9 | 9 | * `security-floor-every-route.test.ts` and `security-floor-errors.test.ts` |
| 10 | 10 | * walk the kinds and statuses one forge answers; this one adds the 429s and |
| @@ -15,6 +15,7 @@ import { afterAll, describe, expect, test } from "bun:test"; | ||
| 15 | 15 | import { mkdtemp, rm } from "node:fs/promises"; |
| 16 | 16 | import { tmpdir } from "node:os"; |
| 17 | 17 | import { join } from "node:path"; |
| 18 | import { createRepo } from "../src/actions/repos.ts"; | |
| 18 | 19 | import { createApp, type App } from "../src/app.ts"; |
| 19 | 20 | import { createSession } from "../src/core/sessions.ts"; |
| 20 | 21 | import { createToken } from "../src/core/tokens.ts"; |
| @@ -60,6 +61,8 @@ async function forge(publicUrl?: string): Promise<Forge> { | ||
| 60 | 61 | const pat = await seedAdmin(app, { username: "pat", email: "[email protected]", password: PASSWORD }); |
| 61 | 62 | if (!pat.ok) throw new Error(pat.error); |
| 62 | 63 | setLimit(app.db, "signin.per_account", TRIES, pat.value.id); |
| 64 | const repo = await createRepo(app, pat.value, { name: "floor", visibility: "public" }); | |
| 65 | if (!repo.ok) throw new Error(String(repo.error)); | |
| 63 | 66 | return { app, servers, origin: publicUrl ?? servers.url, cookie: `forge_session=${createSession(app.db, pat.value.id).token}`, token: createToken(app.db, pat.value.id, "rw", "rw").token, fresh: () => `forge_session=${createSession(app.db, pat.value.id).token}` }; |
| 64 | 67 | } |
| 65 | 68 | |
| @@ -132,6 +135,10 @@ const ROWS: Row[] = [ | ||
| 132 | 135 | { kind: "MCP reply", status: 200, type: "application/json", ask: (f) => mcp(f, { jsonrpc: "2.0", id: 1, method: "tools/list" }) }, |
| 133 | 136 | { kind: "MCP error reply, a JSON-RPC parse error", status: 200, type: "application/json", ask: (f) => mcp(f, "{not json") }, |
| 134 | 137 | { kind: "SSE stream", status: 200, type: "text/event-stream", ask: (f) => get(f, "/api/v1/forge/view", { cookie: f.cookie, accept: "text/event-stream" }) }, |
| 138 | { kind: "git smart-http, refs advertisement", status: 200, type: "application/x-git-upload-pack-advertisement", ask: (f) => get(f, "/pat/floor.git/info/refs?service=git-upload-pack", { "git-protocol": "version=2" }) }, | |
| 139 | { kind: "git smart-http, streamed upload-pack", status: 200, type: "application/x-git-upload-pack-result", ask: (f) => post(f, "/pat/floor.git/git-upload-pack", "0014command=ls-refs\n0000", "application/x-git-upload-pack-request", { "git-protocol": "version=2" }) }, | |
| 140 | { kind: "git smart-http, 400 dumb http", status: 400, ask: (f) => get(f, "/pat/floor.git/info/refs") }, | |
| 141 | { kind: "git smart-http, 401 push without credentials", status: 401, ask: (f) => get(f, "/pat/floor.git/info/refs?service=git-receive-pack") }, | |
| 135 | 142 | { kind: "500 page", status: 500, ask: (f) => failing(f, () => get(f, "/", { cookie: f.cookie, accept: "text/html" })) }, |
| 136 | 143 | { kind: "500 API", status: 500, ask: (f) => failing(f, () => get(f, "/api/v1/user", { cookie: f.cookie })) }, |
| 137 | 144 | { kind: "429 API sign-in", status: 429, ask: async (f) => (await exhaust(f), api(f, "/api/v1/sessions", { username: "pat", password: PASSWORD })) }, |
| @@ -181,7 +188,7 @@ test("the table holds every kind the issue names", () => { | ||
| 181 | 188 | for (const s of [200, 302, 303, 400, 401, 404, 405, 429, 500]) expect(statuses.has(s)).toBe(true); |
| 182 | 189 | const kinds = ROWS.map((r) => r.kind); |
| 183 | 190 | for (const k of ["page", "JSON API answer", "404 page", "500 page", "redirect, form sign-in"]) expect(kinds).toContain(k); |
| 184 | for (const k of ["MCP reply", "SSE stream"]) expect(kinds).toContain(k); | |
| 191 | for (const k of ["MCP reply", "SSE stream", "git smart-http, refs advertisement"]) expect(kinds).toContain(k); | |
| 185 | 192 | expect(kinds.some((k) => k.startsWith("static asset"))).toBe(true); |
| 186 | 193 | }); |
| 187 | 194 |
new above
offline