commit a883551c7c9cb81bb5d5db9da783191dae251c53
parent f82aa86c8e0e11487deaee179c13b7b1c10e2708
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Mon, 9 Nov 2026 18:55:37 -0500
umtool: Open in draft and Save version refuse another site's post (L3 review nit)
The Open in draft page confirms with a plain form, which carries no token, so
another site's page could post the same form. lib/report/sameOrigin.mjs
crossSiteRefusal reads Sec-Fetch-Site and Origin (against Host / the proxy's
X-Forwarded-Host): another site, a sibling site or an opaque origin is a 403;
a terminal or an agent, which sends neither, is not refused here. Unit test.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
4 files changed, 51 insertions(+), 0 deletions(-)
diff --git a/umtool/app/api/report/takes/open/route.ts b/umtool/app/api/report/takes/open/route.ts
@@ -1,5 +1,6 @@
import { invalidateProjects, projectRef } from "@/lib/projects";
import { refuseCaller } from "@/lib/report/caller";
+import { crossSiteRefusal } from "@/lib/report/sameOrigin.mjs";
import { StaleToken, StructureRefused } from "@/lib/report/manifest.mjs";
import { isTakeId } from "@/lib/report/takes.mjs";
import { VersionRefused, openVersion } from "@/lib/report/versions.mjs";
@@ -24,6 +25,9 @@ const local = (v: unknown) => (typeof v === "string" && v.startsWith("/projects/
export async function POST(request: Request) {
const refused = refuseCaller(request, "/api/report/takes/open");
if (refused) return refused;
+ // A plain form carries no token: a write another site's page posts is refused (lib/report/sameOrigin.mjs).
+ const cross = crossSiteRefusal(request.headers);
+ if (cross) return Response.json({ error: cross }, { status: 403 });
const form = isForm(request);
let body: Record<string, unknown> | null = null;
if (form) {
diff --git a/umtool/app/api/report/takes/save/route.ts b/umtool/app/api/report/takes/save/route.ts
@@ -1,5 +1,6 @@
import { invalidateProjects, projectRef } from "@/lib/projects";
import { refuseCaller } from "@/lib/report/caller";
+import { crossSiteRefusal } from "@/lib/report/sameOrigin.mjs";
import { VersionRefused, saveVersion } from "@/lib/report/versions.mjs";
export const dynamic = "force-dynamic";
@@ -14,6 +15,8 @@ export const dynamic = "force-dynamic";
export async function POST(request: Request) {
const refused = refuseCaller(request, "/api/report/takes/save");
if (refused) return refused;
+ const cross = crossSiteRefusal(request.headers);
+ if (cross) return Response.json({ error: cross }, { status: 403 });
const body = (await request.json().catch(() => null)) as { project?: unknown; label?: unknown; force?: unknown } | null;
if (!body || typeof body !== "object") return Response.json({ error: "bad json" }, { status: 400 });
const project = await projectRef(String(body.project ?? ""));
diff --git a/umtool/lib/report/sameOrigin.mjs b/umtool/lib/report/sameOrigin.mjs
@@ -0,0 +1,27 @@
+// A WRITE FROM THIS APP'S OWN PAGES, NOT ANOTHER SITE'S (umtool redesign L3 review): a plain form POST (the Open
+// in draft page's button) carries no token, so a page on another site could post the same form. The browser says
+// where a request comes from -- `Sec-Fetch-Site`, and `Origin` on a POST -- and a write that says another site is
+// refused. A terminal or an agent (curl, the CLI, Playwright's request) sends neither and is not refused here
+// (its Authorization is lib/report/caller.ts's business).
+//
+// Plain ESM so `node --test` reads it.
+
+/**
+ * The sentence to refuse with, or null for a same-origin (or non-browser) request.
+ * @param {{ get(name: string): string | null }} headers
+ */
+export function crossSiteRefusal(headers) {
+ const site = (headers.get("sec-fetch-site") ?? "").trim().toLowerCase();
+ if (site && site !== "same-origin" && site !== "none") return `refused: a ${site} request may not write here`;
+ const origin = (headers.get("origin") ?? "").trim();
+ if (!origin) return null;
+ if (origin === "null") return "refused: a request from an opaque origin may not write here";
+ const host = (headers.get("x-forwarded-host") ?? headers.get("host") ?? "").split(",")[0].trim().toLowerCase();
+ let from = "";
+ try {
+ from = new URL(origin).host.toLowerCase();
+ } catch {
+ return "refused: the request's origin does not parse";
+ }
+ return host && from !== host ? `refused: a request from ${from} may not write to ${host}` : null;
+}
diff --git a/umtool/lib/report/sameOrigin.test.mjs b/umtool/lib/report/sameOrigin.test.mjs
@@ -0,0 +1,17 @@
+// Writes from another site are refused (sameOrigin.mjs): the Open in draft form and Save version.
+import assert from "node:assert/strict";
+import test from "node:test";
+import { crossSiteRefusal } from "./sameOrigin.mjs";
+
+const h = (o) => ({ get: (k) => o[k.toLowerCase()] ?? null });
+
+test("crossSiteRefusal: same-origin and non-browser requests pass; another site, a sibling site and an opaque origin do not", () => {
+ assert.equal(crossSiteRefusal(h({})), null, "curl, the CLI, Playwright's request");
+ assert.equal(crossSiteRefusal(h({ "sec-fetch-site": "same-origin", origin: "http://localhost:3050", host: "localhost:3050" })), null);
+ assert.equal(crossSiteRefusal(h({ "sec-fetch-site": "none" })), null, "typed into the address bar");
+ assert.match(String(crossSiteRefusal(h({ "sec-fetch-site": "cross-site", origin: "https://evil.example", host: "localhost:3050" }))), /cross-site/);
+ assert.match(String(crossSiteRefusal(h({ "sec-fetch-site": "same-site", origin: "http://localhost:3001", host: "localhost:3050" }))), /same-site/);
+ assert.match(String(crossSiteRefusal(h({ origin: "https://evil.example", host: "localhost:3050" }))), /evil\.example/);
+ assert.match(String(crossSiteRefusal(h({ origin: "null", host: "localhost:3050" }))), /opaque/);
+ assert.equal(crossSiteRefusal(h({ origin: "https://umtool.lan", host: "127.0.0.1:3050", "x-forwarded-host": "umtool.lan" })), null, "behind the proxy");
+});