Public: anyone can read this; the crew can change it.

The claim link of a forge made for a client can be regenerated, and the old one stops working #14088

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/14068-the-claim-link-of-a-forge-made-for-a-cli → main 5 commits fork 2 threads · 2 unresolved

  • Merged. scout/14068-the-claim-link-of-a-forge-made-for-a-cli was merged into main as db49867.

Review

Sign in to review this change.
6 files changed +110 −6
docs/features/README.md +1
@@ -343,6 +343,7 @@ Read with the guide page [Hosting forges for others, and getting paid](../guide-
343343 - [A claimed child receives the credential to propose back to its parent](child-proposal-credential.md)
344344 - [A client's monthly bill](forge-bill.md)
345345 - [A forge for a client, from one link](client-forge.md)
346 - [Regenerating a client forge's claim link](regenerate-client-link.md)
346347 - [The client list's three times: sent, opened, first tell](client-link-times.md)
347348 - [A forge whose billing is none](lapsed-forge.md)
348349 - [A forge's claim link as a QR in the terminal](forge-link-qr.md)
src/actions/spawn.ts +6 −4
@@ -64,7 +64,7 @@ import {
6464 import { childSubscription } from "../spawn/child_db.ts";
6565 import { loadKey, open } from "../kernel/secret.ts";
6666 import { loadOrCreateHostKey } from "../ssh/keys.ts";
67 import { claimLink, hasAdmin, mintClaim, PLACEHOLDER_FOUNDER, spawnedOrg } from "../spawn/claim.ts";
67 import { claimLink, hasAdmin, linkOf, mintClaim, PLACEHOLDER_FOUNDER, spawnedOrg } from "../spawn/claim.ts";
6868 import { childPublicUrl, parentOrigin, type Placement, type PlacementKind } from "../spawn/placement.ts";
6969 import { quotaRefusal } from "../spawn/quota.ts";
7070 import { personRefusal, planRefusal } from "../spawn/sleep.ts";
@@ -843,7 +843,7 @@ export async function reissueClaim(
843843 actor: User | undefined,
844844 name: string,
845845 deps: { readonly request: Request; readonly url: URL },
846 ): Promise<Result<{ readonly name: string; readonly claimUrl: string }, SpawnError | { readonly kind: "not_found" }>> {
846 ): Promise<Result<{ readonly name: string; readonly claimUrl: string; readonly expiresAt: string }, SpawnError | { readonly kind: "not_found" }>> {
847847 if (crossOrigin(deps.request, deps.url, app.log)) return err({ kind: "cross_origin" });
848848 const allowed = await mayReissue(app, actor, name);
849849 if (!allowed.ok) return allowed;
@@ -898,7 +898,7 @@ export async function previewReissue(
898898 export async function reissueClaimFor(
899899 app: App,
900900 name: string,
901 ): Promise<Result<{ readonly name: string; readonly claimUrl: string }, SpawnError | { readonly kind: "not_found" }>> {
901 ): Promise<Result<{ readonly name: string; readonly claimUrl: string; readonly expiresAt: string }, SpawnError | { readonly kind: "not_found" }>> {
902902 const ledger = /^[a-z0-9-]{1,39}$/.test(name) ? await readLedger(app, name) : undefined;
903903 if (!ledger || !ledger.done) return err({ kind: "not_found" });
904904 const child = createApp({ dataDir: childDirOf(app, ledger.bodyId) });
@@ -908,7 +908,9 @@ export async function reissueClaimFor(
908908 if (hasAdmin(child.db))
909909 return err({ kind: "refused", reason: "claimed", message: `${name} is already claimed; ask its owner to invite you` });
910910 const token = mintClaim(child.db, spawned.org.id);
911 return ok({ name, claimUrl: claimLink(liveChildUrl(app, name), token) });
911 const expiresAt = linkOf(child.db)?.expiresAt;
912 if (expiresAt === undefined) return fail("the new link was not stored, so it has no expiry to show");
913 return ok({ name, claimUrl: claimLink(liveChildUrl(app, name), token), expiresAt });
912914 } finally {
outdated

The fallback computes a fresh Date.now()+TTL that may differ from the stored expiry, so the page can show a time the link does not have. Use the value mintClaim stored, or return an error if linkOf is missing.

913915 child.close();
914916 }
src/web/pages/claim.ts +1 −1
@@ -88,7 +88,7 @@ interface Values {
8888 type Errors = Partial<Record<"username" | "email" | "password" | "passkey", string>>;
8989
9090 /** `Nov 12, 14:30 UTC`, from an ISO time. */
91 function whenWords(iso: string): string {
91 export function whenWords(iso: string): string {
9292 const d = new Date(iso);
9393 const month = d.toLocaleString("en-US", { month: "short", timeZone: "UTC" });
9494 return `${month} ${d.getUTCDate()}, ${iso.slice(11, 16)} UTC`;
src/web/pages/forges.ts +2 −1
@@ -29,6 +29,7 @@ import { moveToCell } from "../../spawn/move_cell.ts";
2929 import { sealedAt } from "../../spawn/sealed.ts";
3030 import { countRefusals, mayReadRefusals } from "../../core/first_ask_refusals.ts";
3131 import { claimLinkBody } from "./new-forge.ts";
32 import { whenWords } from "./claim.ts";
3233 import { appLinkSummary, appLinkWords } from "../../spawn/app_links.ts";
3334 import { REACH_SETTINGS, reachByForge, type ForgeReach } from "../../actions/child_reach.ts";
3435 import { forgeReachRows } from "./hosted-forges.ts";
@@ -421,7 +422,7 @@ export async function forgeLinkSubmit(ctx: Ctx): Promise<Response> {
421422 ${pageHead(typeof link === "string" ? `A fresh link for ${name}` : `No fresh link for ${name}`)}
422423 <section class="settings-block">
423424 ${typeof link === "string"
outdated

Principle 8 and 1: the raw ISO timestamp is not plain words, and two sentences explain what the page already shows (the old link has stopped is stated by the preview). Format the expiry for a person and keep one sentence.

424 ? claimLinkBody(link, true)
425 ? html`${claimLinkBody(link, true)}<p class="muted" data-expires>Works once, until ${whenWords(String(door.body["expiresAt"] ?? ""))}.</p>`
425426 : html`<p>${String(door.body["message"] ?? "")}</p>
426427 <p class="mt">${btn("Forges you sent", { href: "/forges", size: "sm" })}</p>`}
427428 </section>

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs