Public: anyone can read this; the crew can change it.
The egress gate refuses the forge's own public host zero times: every self-call goes through kernel/outbound #15359
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15350-the-egress-gate-refuses-the-forge-s-own → main 0 commits fork
3 files
changed +40
−4
src/maintain/duties/edge_kept.ts +10 −1
| @@ -6,12 +6,17 @@ | ||
| 6 | 6 | * rule for signed-out HTML keyed on EDGE_VARY). A forge with no edge header says nothing. The |
| 7 | 7 | * URL is `config.url` only, never a host from a request; two small requests a page an hour. Where |
| 8 | 8 | * the forge's gate refuses the host (`X-Forge-Egress: refused`) the answer is unknown and silent. |
| 9 | * | |
| 10 | * A forge in a cell (hosted as an app) does not read its own public host at all: the call is a | |
| 11 | * hairpin through the uplink its gate refuses, one refusal a page an hour (#15350), and the local | |
| 12 | * listener (`outboundFetch` with `self`) would answer without the edge this duty measures. | |
| 9 | 13 | */ |
| 10 | 14 | |
| 11 | 15 | import { fileIssueOnce } from "../../checks/flake.ts"; |
| 12 | 16 | import { getRepo } from "../../core/repos.ts"; |
| 13 | 17 | import { EDGE_VARY } from "../../http/edge_cache.ts"; |
| 14 | 18 | import { ownRepoPath } from "../../kernel/own_repo.ts"; |
| 19 | import { cellProxy } from "../../apps/egress.ts"; | |
| 15 | 20 | import type { Duty, Finding } from "../duty.ts"; |
| 16 | 21 | import { edgeHeader, edgeVerdict, marked } from "../edge_kept.ts"; |
| 17 | 22 | |
| @@ -34,7 +39,10 @@ const body = (path: string, seen: string): string => | ||
| 34 | 39 | `The one fix is the owner's, outside this repository: an edge cache rule that caches signed-out HTML and keys on \`${EDGE_VARY}\`.\n\n` + |
| 35 | 40 | "This issue is filed once per page and left open until it is fixed; the hourly duty `edge-kept` checks again."; |
| 36 | 41 | |
| 37 | export function edgeKept(read: Get = get): Duty { | |
| 42 | /** Whether this forge runs in a cell (hosted as an app): its way out is its parent's gate. */ | |
| 43 | const inACell = (): boolean => cellProxy() !== undefined; | |
| 44 | ||
| 45 | export function edgeKept(read: Get = get, inCell: () => boolean = inACell): Duty { | |
| 38 | 46 | return { |
| 39 | 47 | name: "edge-kept", |
| 40 | 48 | intervalMs: 3_600_000, |
| @@ -43,6 +51,7 @@ export function edgeKept(read: Get = get): Duty { | ||
| 43 | 51 | const url = app?.config.url; |
| 44 | 52 | if (url === undefined || url === "") return { findings: [], actions: ["skipped: this forge does not know its public origin (FORGE_URL)"] }; |
| 45 | 53 | const origin = new URL(url); |
| 54 | if (inCell()) return { findings: [], actions: [`skipped: this forge runs in a cell and does not call its own host ${origin.host}; the edge goes unread (#15350)`] }; | |
| 46 | 55 | const findings: Finding[] = []; |
| 47 | 56 | const actions: string[] = []; |
| 48 | 57 | const [owner = "", name = ""] = ownRepoPath().split("/"); |
test/maintain-edge-kept.test.ts +10 −2
| @@ -43,7 +43,7 @@ test("marked reads the header sharedCache sends", () => { | ||
| 43 | 43 | const dirs: string[] = []; |
| 44 | 44 | afterAll(() => dirs.forEach((d) => rmSync(d, { recursive: true, force: true }))); |
| 45 | 45 | |
| 46 | async function run(read: Get, url: string | undefined = "https://forge.example", withRepo = true) { | |
| 46 | async function run(read: Get, url: string | undefined = "https://forge.example", withRepo = true, inCell = false) { | |
| 47 | 47 | const dir = mkdtempSync(join(tmpdir(), "edge-kept-")); |
| 48 | 48 | dirs.push(dir); |
| 49 | 49 | const app: App = createApp({ dataDir: dir, port: 0, ...(url === undefined ? {} : { url }) }); |
| @@ -51,7 +51,7 @@ async function run(read: Get, url: string | undefined = "https://forge.example", | ||
| 51 | 51 | if (!u.ok) throw new Error(u.error); |
| 52 | 52 | const [, name = "forge"] = ownRepoPath().split("/"); |
| 53 | 53 | if (withRepo) await createRepo(app, u.value, { name, visibility: "private" }); |
| 54 | const duty = edgeDuty(read); | |
| 54 | const duty = edgeDuty(read, () => inCell); | |
| 55 | 55 | const once = () => duty.run({ db: app.db, bus: app.bus, now: new Date(), app }); |
| 56 | 56 | return { app, once }; |
| 57 | 57 | } |
| @@ -68,6 +68,14 @@ test("the duty is on the roster, hourly, and reads only the configured URL", asy | ||
| 68 | 68 | expect(PATHS.length).toBe(2); |
| 69 | 69 | }); |
| 70 | 70 | |
| 71 | test("in a cell it never reads its own public host, and says the edge went unread (#15350)", async () => { | |
| 72 | const seen: string[] = []; | |
| 73 | const r = await (await run(async (u) => (seen.push(u), undefined), "https://forge.example", true, true)).once(); | |
| 74 | expect(seen).toEqual([]); | |
| 75 | expect(r.findings).toEqual([]); | |
| 76 | expect(r.actions).toEqual(["skipped: this forge runs in a cell and does not call its own host forge.example; the edge goes unread (#15350)"]); | |
| 77 | }); | |
| 78 | ||
| 71 | 79 | test("not kept files one issue per page, and a second run adds nothing", async () => { |
| 72 | 80 | const { app, once } = await run(shareable({ "cf-cache-status": "DYNAMIC" })); |
| 73 | 81 | const first = await once(); |
test/outbound-sweep.test.ts +20 −1
| @@ -69,7 +69,7 @@ const OWN_URL = /canonicalUrl|FORGE_APP_URL|FORGE_URL|forgeUrl|config\.url|ownHo | ||
| 69 | 69 | */ |
| 70 | 70 | const OWN_HOST: Record<string, string> = { |
| 71 | 71 | "src/maintain/duties/wait_split.ts": "in a cell it reads loopback alone (#14664); outside one it times its own public URL on purpose, the edge being what it measures", |
| 72 | "src/maintain/duties/edge_kept.ts": "GETs the forge's own public URL on purpose, the edge being what the duty measures (#14663); it says nothing where the gate refuses it (X-Forge-Egress)", | |
| 72 | "src/maintain/duties/edge_kept.ts": "in a cell it skips (#15350); outside one it GETs the forge's own public URL on purpose, the edge being what the duty measures (#14663)", | |
| 73 | 73 | "src/http/server.ts": "the forge's own unix socket; the public URL only names links", |
| 74 | 74 | "src/apps/proxy.ts": "an app's socket or loopback port; the forge URL only builds links for the app", |
| 75 | 75 | "src/apps/toolbar.ts": BROWSER, |
| @@ -83,6 +83,14 @@ const OWN_HOST: Record<string, string> = { | ||
| 83 | 83 | "src/snapshot/verdict.ts": "a command an operator runs, not the forge's process", |
| 84 | 84 | }; |
| 85 | 85 | |
| 86 | /** | |
| 87 | * The files whose bare fetch reaches the forge's own public URL on purpose, from the forge's own | |
| 88 | * process: the edge is what each measures, so the local listener (`outboundFetch` with `self`) | |
| 89 | * would not do. In a cell that call is a hairpin its gate refuses (#15350), so each must ask | |
| 90 | * `inCell()` first and leave the public side unread there. | |
| 91 | */ | |
| 92 | const EDGE_ON_PURPOSE = ["src/maintain/duties/wait_split.ts", "src/maintain/duties/edge_kept.ts"]; | |
| 93 | ||
| 86 | 94 | /** Every non-literal fetch in src, as `file:line`. */ |
| 87 | 95 | async function sweep(): Promise<Map<string, string[]>> { |
| 88 | 96 | const found = new Map<string, string[]>(); |
| @@ -127,6 +135,17 @@ describe("the sweep of src", () => { | ||
| 127 | 135 | } |
| 128 | 136 | }); |
| 129 | 137 | |
| 138 | test("a bare fetch of the forge's own public URL is never made from a cell (#15350)", async () => { | |
| 139 | const unguarded: string[] = []; | |
| 140 | for (const file of EDGE_ON_PURPOSE) { | |
| 141 | const text = await Bun.file(file).text(); | |
| 142 | if (!/cellProxy\(\)/.test(text) || !/inCell\(\)/.test(text)) unguarded.push(file); | |
| 143 | } | |
| 144 | expect(unguarded).toEqual([]); | |
| 145 | for (const [file, why] of Object.entries(OWN_HOST)) | |
| 146 | if (/on purpose/.test(why)) expect([file, EDGE_ON_PURPOSE.includes(file)]).toEqual([file, true]); | |
| 147 | }); | |
| 148 | ||
| 130 | 149 | test("the origin paths a member names go through the guard, not a bare fetch", async () => { |
| 131 | 150 | const found = await sweep(); |
| 132 | 151 | expect(found.get("src/origins/oauth.ts")).toBeUndefined(); |
new above
offline