{"version":306,"agent":"box-grants","message":"abso login --web sends a credential only to the staging website beside the folder's own staging server (Security condition 6, Code Review's Medium on 302). The pairing is the fixed list in web-session.ts; any other server, prod included, is refused and nothing is sent. A box's sign-in takes no --site at all. --site is only for --pat-file, and only http://localhost or 127.0.0.1. webLogin settles the website before it reads the credential, so a refusal reads and sends nothing. Tests: client/test/web-session.test.ts (5), including that every refused case reads no credential and sends no request; tsc exits 0.","time":1792178581623,"timeIso":"2026-10-16T19:23:01.623Z","changes":11,"change":5145,"files":["client/src/main.ts","client/src/web-session.ts","client/test/web-session.test.ts"],"draft":null,"diff":[{"path":"client/src/main.ts","added":15,"removed":8,"diff":"--- a/client/src/main.ts\n+++ b/client/src/main.ts\n@@ -79,7 +79,7 @@\n import { runAmend, runDrop, runFollow, runLabel, runLabels, runPluck } from \"./versions.ts\";\n import { runVisibility } from \"./visibility-commands.ts\";\n import { checkVisitor } from \"./visitor.ts\";\n-import { handoffText, patFromFile, siteFor, webHandoff } from \"./web-session.ts\";\n+import { handoffText, patFromFile, webLogin } from \"./web-session.ts\";\n \n interface CommandDef {\n \treadonly flags: FlagSpec;\n@@ -218,18 +218,25 @@\n \t\t\t\"pat-file\": \"string\",\n \t\t},\n \t\tusage:\n-\t\t\t\"abso login [--no-browser] [--no-ask] [--projects <name,name>] [--role <reader|writer|owner>] [--days <1-90>] | abso login --web [--pat-file <file>] [--site <url>]\",\n+\t\t\t\"abso login [--no-browser] [--no-ask] [--projects <name,name>] [--role <reader|writer|owner>] [--days <1-90>] | abso login --web [--pat-file <file> [--site http://localhost:<port>]]\",\n \t\tabout:\n-\t\t\t\"Sign this box in once: it opens the approve page in your browser with the code filled in, prints the link and the code too, and waits while a person approves the code on the website, choosing the projects, the highest role and how long. Then abso join in any of those projects gives each agent its own key, with no approval. The box's sign-in is kept in your user folder, never in a project folder, and is never printed. No browser opens with --no-browser or ABSO_NO_BROWSER, over SSH, under CI, or on Linux without a display. In an agent's folder on the same server, it also asks a person in that project to approve it (the person who approved the agent's box, else the project's owners), as an abso ask, so nobody has to relay the code; the box can then be granted that project at no more than the agent's own role. --no-ask shows the code only. --web, on staging only, signs a browser in to the website instead: it prints a link that works once, within a minute, and signs whichever browser opens it in as the person who approved this box, but only to the projects the box was granted and at most as a writer, until the box is revoked or ends (or, with --pat-file, as the test account whose PAT that file holds, at most as a writer). It writes issues, replies, answers, groups and announcements, and changes no members, roles, visibility, keys, boxes or settings. The box's sign-in, the PAT and the session never appear; agents never sign in to the website on prod.\",\n+\t\t\t\"Sign this box in once: it opens the approve page in your browser with the code filled in, prints the link and the code too, and waits while a person approves the code on the website, choosing the projects, the highest role and how long. Then abso join in any of those projects gives each agent its own key, with no approval. The box's sign-in is kept in your user folder, never in a project folder, and is never printed. No browser opens with --no-browser or ABSO_NO_BROWSER, over SSH, under CI, or on Linux without a display. In an agent's folder on the same server, it also asks a person in that project to approve it (the person who approved the agent's box, else the project's owners), as an abso ask, so nobody has to relay the code; the box can then be granted that project at no more than the agent's own role. --no-ask shows the code only. --web, on staging only, signs a browser in to the website instead: it prints a link that works once, within a minute, and signs whichever browser opens it in as the person who approved this box, but only to the projects the box was granted and at most as a writer, until the box is revoked or ends (or, with --pat-file, as the test account whose PAT that file holds, at most as a writer). It writes issues, replies, answers, groups and announcements, and changes no members, roles, visibility, keys, boxes or settings. The box's sign-in, the PAT and the session never appear. It goes only to the staging website beside this folder's staging server; any other server, prod included, is refused and nothing is sent. --site, with --pat-file only, points it at a website on this machine (http://localhost or 127.0.0.1).\",\n \t\trun: async (args, env) => {\n \t\t\tconst server = boxServer(args, env);\n \t\t\tif (bool(args, \"web\")) {\n-\t\t\t\tconst site = siteFor(server, str(args, \"site\"));\n \t\t\t\tconst patFile = str(args, \"pat-file\");\n-\t\t\t\tconst record = patFile === undefined ? readBox(server) : undefined;\n-\t\t\t\tif (patFile === undefined && (record === undefined || record.expiresAt <= Date.now()))\n-\t\t\t\t\tthrow new UsageError(`this box isn't signed in to ${server}: abso login first, or --pat-file <file>`);\n-\t\t\t\tconst handoff = await webHandoff(site, patFile === undefined ? record!.credential : patFromFile(patFile));\n+\t\t\t\tconst { handoff, site } = await webLogin({\n+\t\t\t\t\tserver,\n+\t\t\t\t\tsite: str(args, \"site\"),\n+\t\t\t\t\tkind: patFile === undefined ? \"box\" : \"pat\",\n+\t\t\t\t\tcredential: () => {\n+\t\t\t\t\t\tif (patFile !== undefined) return patFromFile(patFile);\n+\t\t\t\t\t\tconst record = readBox(server);\n+\t\t\t\t\t\tif (record === undefined || record.expiresAt <= Date.now())\n+\t\t\t\t\t\t\tthrow new UsageError(`this box isn't signed in to ${server}: abso login first, or --pat-file <file>`);\n+\t\t\t\t\t\treturn record.credential;\n+\t\t\t\t\t},\n+\t\t\t\t});\n \t\t\t\treturn { text: handoffText(handoff, site, patFile === undefined), json: { ...handoff } };\n \t\t\t}\n \t\t\tconst open ="},{"path":"client/src/web-session.ts","added":38,"removed":17,"diff":"--- a/client/src/web-session.ts\n+++ b/client/src/web-session.ts\n@@ -21,30 +21,51 @@\n \treadonly sessionEnds: string;\n }\n \n-/** The website a server's handoff goes to: --site as given (https only), else the staging site beside it. */\n-export function siteFor(server: string, site?: string): string {\n-\tif (site !== undefined) {\n-\t\tlet url: URL;\n-\t\ttry {\n-\t\t\turl = new URL(site);\n-\t\t} catch {\n-\t\t\tthrow new UsageError(\n-\t\t\t\t`--site takes the website's address, like https://abso-website-staging.chrisazy.workers.dev`,\n-\t\t\t);\n-\t\t}\n-\t\tif (url.protocol !== \"https:\" && url.hostname !== \"localhost\" && url.hostname !== \"127.0.0.1\")\n-\t\t\tthrow new UsageError(\"--site has to be https, or this machine\");\n-\t\treturn url.origin;\n-\t}\n+/**\n+ * The website a handoff's credential goes to (Security condition 6, Code Review): the staging website beside the folder's own\n+ * staging server, from the fixed list above, and never an origin from a flag. A server that isn't on the list is refused,\n+ * prod included. --site is only for a test account's PAT on this machine (http://localhost or 127.0.0.1); a box's sign-in\n+ * takes no --site at all.\n+ */\n+export function siteFor(server: string, site: string | undefined, kind: \"box\" | \"pat\"): string {\n \tconst origin = new URL(server).origin;\n \tconst known = STAGING_SITES[origin];\n \tif (known === undefined)\n \t\tthrow new UsageError(\n-\t\t\t`abso login --web is for staging: ${origin} has no staging website beside it that abso knows, and agents never sign in to the website on prod. --site names one.`,\n+\t\t\t`abso login --web is for staging: ${origin} has no staging website beside it that abso knows, and agents never sign in to the website on prod. Nothing was sent.`,\n \t\t);\n-\treturn known;\n+\tif (site === undefined) return known;\n+\tif (kind === \"box\")\n+\t\tthrow new UsageError(`--site isn't taken with a box's sign-in, which goes only to ${known}. Nothing was sent.`);\n+\tlet url: URL | null = null;\n+\ttry {\n+\t\turl = new URL(site);\n+\t} catch {\n+\t\t// Not an address: refused below.\n+\t}\n+\tif (url === null || url.protocol !== \"http:\" || (url.hostname !== \"localhost\" && url.hostname !== \"127.0.0.1\"))\n+\t\tthrow new UsageError(\n+\t\t\t\"--site, with --pat-file, names this machine only (http://localhost:<port> or http://127.0.0.1:<port>). Nothing was sent.\",\n+\t\t);\n+\treturn url.origin;\n }\n \n+/**\n+ * abso login --web: where the credential would go is settled before it is read, so a refusal reads and sends nothing\n+ * (Security). `credential` reads the box's sign-in or the PAT only once the website is one it may go to.\n+ */\n+export async function webLogin(options: {\n+\treadonly server: string;\n+\treadonly site: string | undefined;\n+\t/** A box's sign-in, or a test account's PAT (--pat-file). */\n+\treadonly kind: \"box\" | \"pat\";\n+\treadonly credential: () => string;\n+\treadonly fetcher?: typeof fetch;\n+}): Promise<{ handoff: Handoff; site: string }> {\n+\tconst site = siteFor(options.server, options.site, options.kind);\n+\treturn { handoff: await webHandoff(site, options.credential(), options.fetcher), site };\n+}\n+\n /** A PAT from the file --pat-file names: read here, never printed. */\n export function patFromFile(path: string): string {\n \tlet text: string;"},{"path":"client/test/web-session.test.ts","added":40,"removed":7,"diff":"--- a/client/test/web-session.test.ts\n+++ b/client/test/web-session.test.ts\n@@ -5,20 +5,53 @@\n import { tmpdir } from \"node:os\";\n import { join } from \"node:path\";\n import { test } from \"node:test\";\n-import { handoffText, patFromFile, siteFor, webHandoff } from \"../src/web-session.ts\";\n+import { handoffText, patFromFile, siteFor, webHandoff, webLogin } from \"../src/web-session.ts\";\n \n const SITE = \"https://abso-website-staging.chrisazy.workers.dev\";\n+const STAGING = \"https://abso-staging.chrisazy.workers.dev\";\n const BOX = `abso_bx_${\"C\".repeat(43)}`;\n+const PAT = `abso_pat_${\"A\".repeat(40)}`;\n const NOW = Date.UTC(2026, 9, 16, 9, 0, 0);\n \n-test(\"the website is the staging one beside the server, or --site; prod has none, since agents never sign in there\", () => {\n-\tassert.equal(siteFor(\"https://abso-staging.chrisazy.workers.dev\"), SITE);\n-\tassert.equal(siteFor(\"https://avcs-staging.chrisazy.workers.dev/\"), SITE);\n-\tassert.throws(() => siteFor(\"https://api.abso.dev\"), /for staging.*never sign in to the website on prod/);\n-\tassert.equal(siteFor(\"https://api.abso.dev\", \"http://localhost:8871/x\"), \"http://localhost:8871\");\n-\tassert.throws(() => siteFor(\"https://api.abso.dev\", \"http://elsewhere.example\"), /https/);\n+test(\"the credential goes only to the staging website beside the folder's staging server (Security condition 6)\", () => {\n+\tassert.equal(siteFor(STAGING, undefined, \"box\"), SITE);\n+\tassert.equal(siteFor(\"https://avcs-staging.chrisazy.workers.dev/\", undefined, \"pat\"), SITE);\n+\t// A server that isn't staging is refused, prod included, whatever is asked.\n+\tassert.throws(\n+\t\t() => siteFor(\"https://api.abso.dev\", undefined, \"box\"),\n+\t\t/for staging.*never sign in to the website on prod/,\n+\t);\n+\tassert.throws(() => siteFor(\"https://api.abso.dev\", \"http://localhost:8871\", \"pat\"), /for staging/);\n+\t// A box's sign-in takes no --site, not even the staging website's own address.\n+\tassert.throws(() => siteFor(STAGING, SITE, \"box\"), /isn't taken with a box's sign-in/);\n+\tassert.throws(() => siteFor(STAGING, \"http://localhost:8871\", \"box\"), /isn't taken with a box's sign-in/);\n+\t// A PAT may name this machine over http, and nothing else.\n+\tassert.equal(siteFor(STAGING, \"http://localhost:8871/x\", \"pat\"), \"http://localhost:8871\");\n+\tassert.equal(siteFor(STAGING, \"http://127.0.0.1:8871\", \"pat\"), \"http://127.0.0.1:8871\");\n+\tfor (const elsewhere of [\"https://anywhere.example\", SITE, \"https://localhost:8871\", \"not a url\"])\n+\t\tassert.throws(() => siteFor(STAGING, elsewhere, \"pat\"), /names this machine only/, elsewhere);\n });\n \n+test(\"a refused handoff reads no credential and sends no request\", async () => {\n+\tconst sent: string[] = [];\n+\tconst fetcher = (async (url: string) => (sent.push(url), Response.json({}))) as unknown as typeof fetch;\n+\tlet read = 0;\n+\tconst credential = () => (read++, BOX);\n+\tfor (const asked of [\n+\t\t{ server: \"https://api.abso.dev\", site: undefined, kind: \"box\" as const },\n+\t\t{ server: STAGING, site: \"https://anywhere.example\", kind: \"box\" as const },\n+\t\t{ server: STAGING, site: SITE, kind: \"box\" as const },\n+\t\t{ server: \"https://api.abso.dev\", site: \"http://localhost:8871\", kind: \"pat\" as const },\n+\t\t{ server: STAGING, site: \"https://anywhere.example\", kind: \"pat\" as const },\n+\t])\n+\t\tawait assert.rejects(webLogin({ ...asked, credential, fetcher }), /Nothing was sent/, JSON.stringify(asked));\n+\tassert.deepEqual(sent, []);\n+\tassert.equal(read, 0);\n+\t// Allowed, it goes to the staging website only.\n+\tawait webLogin({ server: STAGING, site: undefined, kind: \"pat\", credential: () => PAT, fetcher }).catch(() => {});\n+\tassert.deepEqual(sent, [`${SITE}/login/handoff`]);\n+});\n+\n test(\"the credential goes in Authorization only, and the answer is the one link and who it signs in as\", async () => {\n \tconst seen: { url: string; authorization: string | null; body: unknown }[] = [];\n \tconst fetcher = (async (url: string, init: RequestInit) => {"}],"ci":null}