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

Merged opened this

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

Merged

scout/forge:scout/15967-every-kind-of-response-the-forge-writes → main 0 commits fork

  • Merged. scout/15967-every-kind-of-response-the-forge-writes was merged into main as 34837fc.

Review

Sign in to review this change.
1 file changed +14 −7
test/security-floor-kinds.test.ts +14 −7
@@ -1,10 +1,10 @@
11 /**
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.
88 *
99 * `security-floor-every-route.test.ts` and `security-floor-errors.test.ts`
1010 * 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";
1515 import { mkdtemp, rm } from "node:fs/promises";
1616 import { tmpdir } from "node:os";
1717 import { join } from "node:path";
18 import { createRepo } from "../src/actions/repos.ts";
1819 import { createApp, type App } from "../src/app.ts";
1920 import { createSession } from "../src/core/sessions.ts";
2021 import { createToken } from "../src/core/tokens.ts";
@@ -60,6 +61,8 @@ async function forge(publicUrl?: string): Promise<Forge> {
6061 const pat = await seedAdmin(app, { username: "pat", email: "[email protected]", password: PASSWORD });
6162 if (!pat.ok) throw new Error(pat.error);
6263 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));
6366 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}` };
6467 }
6568
@@ -132,6 +135,10 @@ const ROWS: Row[] = [
132135 { kind: "MCP reply", status: 200, type: "application/json", ask: (f) => mcp(f, { jsonrpc: "2.0", id: 1, method: "tools/list" }) },
133136 { kind: "MCP error reply, a JSON-RPC parse error", status: 200, type: "application/json", ask: (f) => mcp(f, "{not json") },
134137 { 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") },
135142 { kind: "500 page", status: 500, ask: (f) => failing(f, () => get(f, "/", { cookie: f.cookie, accept: "text/html" })) },
136143 { kind: "500 API", status: 500, ask: (f) => failing(f, () => get(f, "/api/v1/user", { cookie: f.cookie })) },
137144 { 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", () => {
181188 for (const s of [200, 302, 303, 400, 401, 404, 405, 429, 500]) expect(statuses.has(s)).toBe(true);
182189 const kinds = ROWS.map((r) => r.kind);
183190 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);
185192 expect(kinds.some((k) => k.startsWith("static asset"))).toBe(true);
186193 });
187194

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs