{"draft":null,"from":304,"to":318,"files":[{"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;"}],"unmatched":[]}