3 files, 93 lines added, 32 removed.
--- a/client/src/main.ts
+++ b/client/src/main.ts
@@ -79,7 +79,7 @@
7979import { runAmend, runDrop, runFollow, runLabel, runLabels, runPluck } from "./versions.ts"; 8080import { runVisibility } from "./visibility-commands.ts"; 8181import { checkVisitor } from "./visitor.ts"; 82−import { handoffText, patFromFile, siteFor, webHandoff } from "./web-session.ts";
82+import { handoffText, patFromFile, webLogin } from "./web-session.ts"; 8484interface CommandDef { 8585 readonly flags: FlagSpec; @@ -218,18 +218,25 @@
218218 "pat-file": "string", 221− "abso login [--no-browser] [--no-ask] [--projects <name,name>] [--role <reader|writer|owner>] [--days <1-90>] | abso login --web [--pat-file <file>] [--site <url>]",
221+ "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>]]", 223− "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.",
223+ "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).", 224224 run: async (args, env) => { 225225 const server = boxServer(args, env); 226226 if (bool(args, "web")) { 227− const site = siteFor(server, str(args, "site"));
228227 const patFile = str(args, "pat-file"); 229− const record = patFile === undefined ? readBox(server) : undefined;
230− if (patFile === undefined && (record === undefined || record.expiresAt <= Date.now()))
231− throw new UsageError(`this box isn't signed in to ${server}: abso login first, or --pat-file <file>`);
232− const handoff = await webHandoff(site, patFile === undefined ? record!.credential : patFromFile(patFile));
228+ const { handoff, site } = await webLogin({ 230+ site: str(args, "site"), 231+ kind: patFile === undefined ? "box" : "pat", 233+ if (patFile !== undefined) return patFromFile(patFile); 234+ const record = readBox(server); 235+ if (record === undefined || record.expiresAt <= Date.now()) 236+ throw new UsageError(`this box isn't signed in to ${server}: abso login first, or --pat-file <file>`); 237+ return record.credential; 233240 return { text: handoffText(handoff, site, patFile === undefined), json: { ...handoff } }; --- a/client/src/web-session.ts
+++ b/client/src/web-session.ts
@@ -21,30 +21,51 @@
2121 readonly sessionEnds: string; 24−/** The website a server's handoff goes to: --site as given (https only), else the staging site beside it. */
25−export function siteFor(server: string, site?: string): string {
26− if (site !== undefined) {
27− let url: URL;
28− try {
29− url = new URL(site);
30− } catch {
31− throw new UsageError(
32− `--site takes the website's address, like https://abso-website-staging.chrisazy.workers.dev`,
33− );
34− }
35− if (url.protocol !== "https:" && url.hostname !== "localhost" && url.hostname !== "127.0.0.1")
36− throw new UsageError("--site has to be https, or this machine");
37− return url.origin;
38− }
25+ * The website a handoff's credential goes to (Security condition 6, Code Review): the staging website beside the folder's own 26+ * staging server, from the fixed list above, and never an origin from a flag. A server that isn't on the list is refused, 27+ * 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 28+ * takes no --site at all. 30+export function siteFor(server: string, site: string | undefined, kind: "box" | "pat"): string { 3931 const origin = new URL(server).origin; 4032 const known = STAGING_SITES[origin]; 4133 if (known === undefined) 4234 throw new UsageError( 43− `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.`,
35+ `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.`, 45− return known;
37+ if (site === undefined) return known; 39+ throw new UsageError(`--site isn't taken with a box's sign-in, which goes only to ${known}. Nothing was sent.`); 40+ let url: URL | null = null; 44+ // Not an address: refused below. 46+ if (url === null || url.protocol !== "http:" || (url.hostname !== "localhost" && url.hostname !== "127.0.0.1")) 47+ throw new UsageError( 48+ "--site, with --pat-file, names this machine only (http://localhost:<port> or http://127.0.0.1:<port>). Nothing was sent.", 54+ * abso login --web: where the credential would go is settled before it is read, so a refusal reads and sends nothing 55+ * (Security). `credential` reads the box's sign-in or the PAT only once the website is one it may go to. 57+export async function webLogin(options: { 58+ readonly server: string; 59+ readonly site: string | undefined; 60+ /** A box's sign-in, or a test account's PAT (--pat-file). */ 61+ readonly kind: "box" | "pat"; 62+ readonly credential: () => string; 63+ readonly fetcher?: typeof fetch; 64+}): Promise<{ handoff: Handoff; site: string }> { 65+ const site = siteFor(options.server, options.site, options.kind); 66+ return { handoff: await webHandoff(site, options.credential(), options.fetcher), site }; 4869/** A PAT from the file --pat-file names: read here, never printed. */ 4970export function patFromFile(path: string): string { --- a/client/test/web-session.test.ts
+++ b/client/test/web-session.test.ts
@@ -5,20 +5,53 @@
55import { tmpdir } from "node:os"; 66import { join } from "node:path"; 77import { test } from "node:test"; 8−import { handoffText, patFromFile, siteFor, webHandoff } from "../src/web-session.ts";
8+import { handoffText, patFromFile, siteFor, webHandoff, webLogin } from "../src/web-session.ts"; 1010const SITE = "https://abso-website-staging.chrisazy.workers.dev"; 11+const STAGING = "https://abso-staging.chrisazy.workers.dev"; 1112const BOX = `abso_bx_${"C".repeat(43)}`; 13+const PAT = `abso_pat_${"A".repeat(40)}`; 1214const NOW = Date.UTC(2026, 9, 16, 9, 0, 0); 14−test("the website is the staging one beside the server, or --site; prod has none, since agents never sign in there", () => {
15− assert.equal(siteFor("https://abso-staging.chrisazy.workers.dev"), SITE);
16− assert.equal(siteFor("https://avcs-staging.chrisazy.workers.dev/"), SITE);
17− assert.throws(() => siteFor("https://api.abso.dev"), /for staging.*never sign in to the website on prod/);
18− assert.equal(siteFor("https://api.abso.dev", "http://localhost:8871/x"), "http://localhost:8871");
19− assert.throws(() => siteFor("https://api.abso.dev", "http://elsewhere.example"), /https/);
16+test("the credential goes only to the staging website beside the folder's staging server (Security condition 6)", () => { 17+ assert.equal(siteFor(STAGING, undefined, "box"), SITE); 18+ assert.equal(siteFor("https://avcs-staging.chrisazy.workers.dev/", undefined, "pat"), SITE); 19+ // A server that isn't staging is refused, prod included, whatever is asked. 21+ () => siteFor("https://api.abso.dev", undefined, "box"), 22+ /for staging.*never sign in to the website on prod/, 24+ assert.throws(() => siteFor("https://api.abso.dev", "http://localhost:8871", "pat"), /for staging/); 25+ // A box's sign-in takes no --site, not even the staging website's own address. 26+ assert.throws(() => siteFor(STAGING, SITE, "box"), /isn't taken with a box's sign-in/); 27+ assert.throws(() => siteFor(STAGING, "http://localhost:8871", "box"), /isn't taken with a box's sign-in/); 28+ // A PAT may name this machine over http, and nothing else. 29+ assert.equal(siteFor(STAGING, "http://localhost:8871/x", "pat"), "http://localhost:8871"); 30+ assert.equal(siteFor(STAGING, "http://127.0.0.1:8871", "pat"), "http://127.0.0.1:8871"); 31+ for (const elsewhere of ["https://anywhere.example", SITE, "https://localhost:8871", "not a url"]) 32+ assert.throws(() => siteFor(STAGING, elsewhere, "pat"), /names this machine only/, elsewhere); 35+test("a refused handoff reads no credential and sends no request", async () => { 36+ const sent: string[] = []; 37+ const fetcher = (async (url: string) => (sent.push(url), Response.json({}))) as unknown as typeof fetch; 39+ const credential = () => (read++, BOX); 40+ for (const asked of [ 41+ { server: "https://api.abso.dev", site: undefined, kind: "box" as const }, 42+ { server: STAGING, site: "https://anywhere.example", kind: "box" as const }, 43+ { server: STAGING, site: SITE, kind: "box" as const }, 44+ { server: "https://api.abso.dev", site: "http://localhost:8871", kind: "pat" as const }, 45+ { server: STAGING, site: "https://anywhere.example", kind: "pat" as const }, 47+ await assert.rejects(webLogin({ ...asked, credential, fetcher }), /Nothing was sent/, JSON.stringify(asked)); 48+ assert.deepEqual(sent, []); 49+ assert.equal(read, 0); 50+ // Allowed, it goes to the staging website only. 51+ await webLogin({ server: STAGING, site: undefined, kind: "pat", credential: () => PAT, fetcher }).catch(() => {}); 52+ assert.deepEqual(sent, [`${SITE}/login/handoff`]); 2255test("the credential goes in Authorization only, and the answer is the one link and who it signs in as", async () => { 2356 const seen: { url: string; authorization: string | null; body: unknown }[] = []; 2457 const fetcher = (async (url: string, init: RequestInit) => {