{"version":88,"agent":"pinch","message":"Every request a folder's Api makes goes through one send(): a folder that reads signed out sends only GETs and follows no redirect on every path, box runs and serve included.","time":1791618771034,"timeIso":"2026-10-10T07:52:51.034Z","changes":3,"change":1035,"files":["client/src/api.ts","client/src/box-run.ts","client/test/visitor.test.ts"],"draft":null,"diff":[{"path":"client/src/api.ts","added":30,"removed":18,"diff":"--- a/client/src/api.ts\n+++ b/client/src/api.ts\n@@ -179,6 +179,17 @@\n \t\t};\n \t}\n \n+\t/**\n+\t * Every request this Api makes goes through here. In a visitor folder it never sends anything but a GET,\n+\t * and follows no redirect, so nothing it sends goes anywhere it didn't name (headers() adds no sign-in).\n+\t */\n+\tsend(url: string, init: RequestInit = {}): Promise<Response> {\n+\t\tif (!this.config.visitor) return fetch(url, init);\n+\t\tif ((init.method ?? \"GET\") !== \"GET\")\n+\t\t\treturn Promise.reject(new ApiError(\"a folder that reads signed out sends only reads\"));\n+\t\treturn fetch(url, { ...init, redirect: \"error\" });\n+\t}\n+\n \tasync json<T>(\n \t\tmethod: \"GET\" | \"POST\",\n \t\tpath: string,\n@@ -187,9 +198,8 @@\n \t\tatLeastMs = 0,\n \t): Promise<T> {\n \t\tlet res: Response | undefined;\n-\t\t// A visitor folder only reads, and follows no redirect, so nothing it sends goes anywhere it didn't name.\n-\t\tconst visitor = this.config.visitor === true;\n-\t\tif (visitor && method !== \"GET\") throw new ApiError(`${path}: a folder that reads signed out sends only reads`);\n+\t\tif (this.config.visitor && method !== \"GET\")\n+\t\t\tthrow new ApiError(`${path}: a folder that reads signed out sends only reads`);\n \t\tconst sent = body === undefined ? undefined : JSON.stringify(body);\n \t\tconst timeoutMs = Math.max(atLeastMs, timeoutFor(this.timeoutMs, sent));\n \t\t// A connection that never opened is tried once more, IPv4 first (#37, GAME - UI/UX: one IPv6\n@@ -197,11 +207,10 @@\n \t\t// a POST is as safe to send again as a GET.\n \t\tfor (let attempt = 0; res === undefined; attempt++) {\n \t\t\ttry {\n-\t\t\t\tres = await fetch(this.url(path, server), {\n+\t\t\t\tres = await this.send(this.url(path, server), {\n \t\t\t\t\tmethod,\n \t\t\t\t\theaders: this.headers(sent === undefined ? undefined : \"application/json\"),\n \t\t\t\t\t...(sent === undefined ? {} : { body: sent }),\n-\t\t\t\t\t...(visitor ? { redirect: \"error\" as const } : {}),\n \t\t\t\t\tsignal: AbortSignal.timeout(timeoutMs),\n \t\t\t\t});\n \t\t\t} catch (err) {\n@@ -290,7 +299,7 @@\n \t\t});\n \t\tlet res: Response;\n \t\ttry {\n-\t\t\tres = await fetch(`${this.url(\"/serve\")}?${q}`, {\n+\t\t\tres = await this.send(`${this.url(\"/serve\")}?${q}`, {\n \t\t\t\tmethod: \"POST\",\n \t\t\t\theaders: this.headers(),\n \t\t\t\tsignal: AbortSignal.timeout(20 * 60_000),\n@@ -311,13 +320,16 @@\n \tasync prep(command: string, tarGz: Uint8Array<ArrayBuffer>): Promise<PrepAnswer> {\n \t\tlet res: Response;\n \t\ttry {\n-\t\t\tres = await fetch(`${this.url(this.agentPath(\"prep\"))}?cmd=${encodeURIComponent(command)}${boxQuery(this.box)}`, {\n-\t\t\t\tmethod: \"POST\",\n-\t\t\t\theaders: this.headers(\"application/gzip\"),\n-\t\t\t\tbody: tarGz,\n-\t\t\t\t// A setup command can take minutes (npm ci, a browser download).\n-\t\t\t\tsignal: AbortSignal.timeout(30 * 60_000),\n-\t\t\t});\n+\t\t\tres = await this.send(\n+\t\t\t\t`${this.url(this.agentPath(\"prep\"))}?cmd=${encodeURIComponent(command)}${boxQuery(this.box)}`,\n+\t\t\t\t{\n+\t\t\t\t\tmethod: \"POST\",\n+\t\t\t\t\theaders: this.headers(\"application/gzip\"),\n+\t\t\t\t\tbody: tarGz,\n+\t\t\t\t\t// A setup command can take minutes (npm ci, a browser download).\n+\t\t\t\t\tsignal: AbortSignal.timeout(30 * 60_000),\n+\t\t\t\t},\n+\t\t\t);\n \t\t} catch (err) {\n \t\t\tconst e = err as Error;\n \t\t\tthrow new ApiError(\n@@ -333,7 +345,7 @@\n \tasync unprep(): Promise<boolean> {\n \t\tlet res: Response;\n \t\ttry {\n-\t\t\tres = await fetch(\n+\t\t\tres = await this.send(\n \t\t\t\t`${this.url(this.agentPath(\"prep\"))}${this.box ? `?box=${encodeURIComponent(this.box)}` : \"\"}`,\n \t\t\t\t{ method: \"DELETE\", headers: this.headers(), signal: AbortSignal.timeout(this.timeoutMs) },\n \t\t\t);\n@@ -369,7 +381,7 @@\n \tasync bytes(method: \"GET\" | \"PUT\", path: string, body?: Uint8Array): Promise<Uint8Array> {\n \t\tlet res: Response;\n \t\ttry {\n-\t\t\tres = await fetch(this.url(path), {\n+\t\t\tres = await this.send(this.url(path), {\n \t\t\t\tmethod,\n \t\t\t\theaders: this.headers(body === undefined ? undefined : \"application/octet-stream\"),\n \t\t\t\t...(body === undefined ? {} : { body: body as Uint8Array<ArrayBuffer> }),\n@@ -491,7 +503,7 @@\n \t\tconst path = this.agentPath(\"attachments\");\n \t\tlet res: Response;\n \t\ttry {\n-\t\t\tres = await fetch(this.url(path, this.issuesServer), {\n+\t\t\tres = await this.send(this.url(path, this.issuesServer), {\n \t\t\t\tmethod: \"POST\",\n \t\t\t\theaders: { ...this.headers(\"application/octet-stream\"), \"x-abso-name\": encodeURIComponent(name) },\n \t\t\t\tbody: bytes as Uint8Array<ArrayBuffer>,\n@@ -538,7 +550,7 @@\n \t\tconst url = `${this.attachmentUrl(id)}${source ? \"/source\" : \"\"}`;\n \t\tlet res: Response;\n \t\ttry {\n-\t\t\tres = await fetch(url, {\n+\t\t\tres = await this.send(url, {\n \t\t\t\theaders: this.headers(),\n \t\t\t\tsignal: AbortSignal.timeout(Math.max(this.timeoutMs, 120_000)),\n \t\t\t});\n@@ -936,7 +948,7 @@\n \tasync logs(id: string, io: RunIO): Promise<number> {\n \t\tlet res: Response;\n \t\ttry {\n-\t\t\tres = await fetch(followUrl(this, id, { at: 0, errAt: 0 }), { headers: this.headers() });\n+\t\t\tres = await this.send(followUrl(this, id, { at: 0, errAt: 0 }), { headers: this.headers() });\n \t\t} catch (err) {\n \t\t\tconst e = err as Error;\n \t\t\tthrow new ApiError("},{"path":"client/src/box-run.ts","added":2,"removed":2,"diff":"--- a/client/src/box-run.ts\n+++ b/client/src/box-run.ts\n@@ -150,7 +150,7 @@\n \t\ttry {\n \t\t\t// stderr=split: the box's stderr comes apart from stdout (7a5a111); older servers ignore it.\n \t\t\t// replace=1: stop the runs still going in the box first; without it the server answers 409 (#25).\n-\t\t\tconst answer = await fetch(\n+\t\t\tconst answer = await api.send(\n \t\t\t\t`${api.url(api.agentPath(\"run\"))}?cmd=${encodeURIComponent(command)}&stderr=split${replace ? \"&replace=1\" : \"\"}${fresh ? \"&fresh=1\" : \"\"}${boxQuery(api.box)}`,\n \t\t\t\t{\n \t\t\t\t\tmethod: \"POST\",\n@@ -216,7 +216,7 @@\n \t\tonReconnect?.(last, attempt + 1);\n \t\tawait new Promise((ok) => setTimeout(ok, delay));\n \t\ttry {\n-\t\t\tconst res = await fetch(followUrl(api, id, seen), { headers: api.headers() });\n+\t\t\tconst res = await api.send(followUrl(api, id, seen), { headers: api.headers() });\n \t\t\tif (res.status === 404)\n \t\t\t\tthrow new ApiError(\n \t\t\t\t\t`the run broke off (${why}) and is gone from the box: ${errorSentence(await res.text())}`,"},{"path":"client/test/visitor.test.ts","added":24,"removed":0,"diff":"--- a/client/test/visitor.test.ts\n+++ b/client/test/visitor.test.ts\n@@ -16,6 +16,7 @@\n import { tmpdir } from \"node:os\";\n import { join, resolve } from \"node:path\";\n import { after, before, describe, it } from \"node:test\";\n+import { Api } from \"../src/api.ts\";\n import { writeBox } from \"../src/box.ts\";\n import { writeConfig } from \"../src/config.ts\";\n import { isPublic } from \"../src/join-commands.ts\";\n@@ -257,6 +258,29 @@\n \t\tassert.match(runs[0]!.stderr, /isn't signed in to .*abso login signs it in/);\n \t});\n \n+\tit(\"every request its Api makes goes through one send: reads only, no redirect, no sign-in\", async () => {\n+\t\tconst real = globalThis.fetch;\n+\t\tconst calls: RequestInit[] = [];\n+\t\tglobalThis.fetch = (async (_input: unknown, init?: RequestInit) => {\n+\t\t\tcalls.push(init ?? {});\n+\t\t\treturn new Response(\"{}\", { status: 200 });\n+\t\t}) as typeof fetch;\n+\t\ttry {\n+\t\t\tconst visitor = new Api({ server: url, project: \"abso-core\", agent: \"\", visitor: true, token: TOKEN });\n+\t\t\tawait visitor.send(`${url}/p/abso-core/serve`, { headers: visitor.headers() });\n+\t\t\tawait assert.rejects(visitor.send(`${url}/p/abso-core/a/x/run`, { method: \"POST\" }), /sends only reads/);\n+\t\t\tconst member = new Api({ server: url, project: \"abso-core\", agent: \"x\", token: TOKEN });\n+\t\t\tawait member.send(`${url}/p/abso-core/serve`, { headers: member.headers() });\n+\t\t} finally {\n+\t\t\tglobalThis.fetch = real;\n+\t\t}\n+\t\tassert.equal(calls.length, 2);\n+\t\tassert.equal(calls[0]!.redirect, \"error\");\n+\t\tassert.equal(new Headers(calls[0]!.headers).get(\"authorization\"), null);\n+\t\tassert.equal(calls[1]!.redirect, undefined);\n+\t\tassert.equal(new Headers(calls[1]!.headers).get(\"authorization\"), `Bearer ${TOKEN}`);\n+\t});\n+\n \tit(\"runs only its reads: every other command is refused before any call, and a new command fails here\", async () => {\n \t\tconst sorted = new Set([...Object.keys(VISITOR_READS), ...VISITOR_ELSEWHERE, ...REFUSED]);\n \t\tfor (const name of Object.keys(commandTable()))"}],"ci":null}