Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed

Versions 302 to 318

Compare

+44 −20 in 2 places
Lines 21–71 at 318 (were 21–50 at 302)
2121 readonly sessionEnds: string;
2222}
2323
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− }
24+/**
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.
29+ */
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.`,
4436 );
45− return known;
37+ if (site === undefined) return known;
38+ if (kind === "box")
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;
41+ try {
42+ url = new URL(site);
43+ } catch {
44+ // Not an address: refused below.
45+ }
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.",
49+ );
50+ return url.origin;
4651}
4752
53+/**
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.
56+ */
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 };
67+}
4869/** A PAT from the file --pat-file names: read here, never printed. */
4970export function patFromFile(path: string): string {
5071 let text: string;
Lines 128–141 at 318 (were 107–117 at 302)
107128 };
108129}
109130
110−/** What abso login --web says: the one link, how long it works, and who it signs in as. */
111−export function handoffText(h: Handoff, site: string, now = Date.now()): string {
131+/** What abso login --web says: the one link, how long it works, who it signs in as, and what it reaches (Security). */
132+export function handoffText(h: Handoff, site: string, boxed = true, now = Date.now()): string {
112133 const seconds = Math.max(0, Math.round((Date.parse(h.expiresAt) - now) / 1000));
134+ const reach = boxed
135+ ? "only to the projects this box was granted, at most as a writer, until the box is revoked or ends"
136+ : "at most as a writer";
113137 return [
114− `Open this link in your browser within ${seconds} seconds. It signs that browser in to ${site} as ${h.name}, until ${h.sessionEnds}, and works once:`,
138+ `Open this link in your browser within ${seconds} seconds. It signs that browser in to ${site} as ${h.name}, until ${h.sessionEnds}, and works once. It reaches ${reach}:`,
115139 h.url,
116140 ].join("\n");
117141}
MCP
compare on this site's /mcp
CLI
abso diff 302 318 client/src/web-session.ts --json
JSON
/christopher/abso-core/compare/302..318?file=client%2Fsrc%2Fweb-session.ts&format=json