// WHO MAY PRESS (lane posts-library, review 1): the Posts library's press // routes write every press as the OPERATOR's, so they take a press only from // what the operator uses — umtool's own page, in a browser. // // A request is the page's when it carries what a browser sends and a page // cannot forge (`Origin` on a write, `Sec-Fetch-Site` on every request: // lib/report/writeGuard.mjs fromBrowser) AND is same-origin to a host that is // this machine (lib/report/sameOrigin.mjs crossSiteRefusal). Anything else — // curl, a script, an agent, the editor's server, with or without a bearer — // is sent to the doors where a caller says who it is: `pnpm ops` and `umtool // library`, whose `by` is "agent" unless told. // // The proxy's guard (umtool/proxy.ts) lets a request with neither header // through on purpose (the CLI and the editor write other routes that way), so // this is asked HERE, by every press route, before the body is read. // // Plain ESM. import { crossSiteRefusal } from "../report/sameOrigin.mjs"; import { fromBrowser } from "../report/writeGuard.mjs"; export const AGENTS_GO_ELSEWHERE = "This route is the Posts library page's: its presses are written as the operator's, so it takes them from umtool's own page in a browser only. An agent or a script uses `pnpm ops judge-trending` / `watch-trending` / `purge-trending` / `organise-trending` / `publish-trending` or `umtool library`, and says \"by\": \"agent\"."; /** * Why a request may not press, or null when it is the page's. * @param {{ get(name: string): string | null }} headers * @param {Record} [env] * @returns {{ status: 403, error: string } | null} */ export function pressRefusal(headers, env = process.env) { if (headers.get("authorization") !== null) return { status: 403, error: AGENTS_GO_ELSEWHERE }; if (!fromBrowser(headers)) return { status: 403, error: AGENTS_GO_ELSEWHERE }; const cross = crossSiteRefusal(headers, env); return cross ? { status: 403, error: cross } : null; }