Public: anyone can read this; the crew can change it.
Publishing an app from the tab forge mints the visitor principal, and only then #18243
Its check is red, 9h 26m ago
check failed: 1 of 2242 tests — "the cookie floor > every cookie constructed under src/ reaches the helper, or is named with its reason"
torque/forge:torque/18216-publishing-an-app-from-the-tab-forge-min → main 2 commits fork
6 files
changed +158
−4
docs/features/returning-visitors.md +3
| @@ -25,3 +25,6 @@ Settings → Traffic ("Who comes back"), the Billing page ("What led to a forge" | ||
| 25 | 25 | - **Becoming someone.** Spawning a forge (`POST /api/v1/forges`) links the request's cookie id to the forge name |
| 26 | 26 | (`started a forge`; `paid` when a gift/plan code was redeemed). Stripe-paid checkouts are not linked yet. |
| 27 | 27 | - `/privacy` says it in three lines. |
| 28 | - **Not the visitor principal.** A person with no account who makes something (a note on an app's page, a game client link, | |
| 29 | or publishing a tab forge app as a link, #18216) gets a separate signed `forge_maker` cookie (`src/core/visitors.ts`), | |
| 30 | minted only at that moment and capped by `VISITOR_CAPS`. It shares no id, key or table with `forge_visitor`. |
docs/features/tabforge.md +1 −1
| @@ -18,6 +18,6 @@ The page is `src/web/pages/tabforge.ts`; the words are `src/web/tabforge/words.t | ||
| 18 | 18 | |
| 19 | 19 | An app made in a tab (`/tab`, format `src/tab/blocks.ts`) can be sent to the forge as one read-only link that opens on any device, with no login. The app's page in the tab offers **Get a link** beside its source: a plain form whose hidden field carries the app's JSON, so it works with script off. `POST /tabforge-link` (`src/web/pages/tabforge-link.ts`, logic in `src/tab/share.ts`) checks it is same-origin, reads at most 80 KB, validates it with `decodeApp` (its `LIMITS` apply), stores the decoded app only, never its entries, in `tab_shared`, and answers a 16-character random id as `/tabforge-link/<id>`. A spec that does not decode stores nothing. `GET /tabforge-link/<id>` draws the app read-only (the preview renderer: no forms, no entries), escaped, with the floor's headers; an unknown or malformed id is the forge's one 404. |
| 20 | 20 | |
| 21 | The route sits outside `/tabforge/` and `/tab/f/` on purpose: a service worker in either scope would answer for it in a browser that started a tab forge. It is an open door for strangers, so it is limited by rate, not by count: 10 posts a minute per address (the `share` door in `src/http/strangers.ts`), taken before the body is read. Storage is bounded the other way: the forge keeps the newest 5000 links and the oldest go as a new one is made, so a link can stop opening once enough newer ones exist, and no one can fill the table and lock the door. It mints no account and no visitor principal, and there is no way to edit or delete a link yet. | |
| 21 | The route sits outside `/tabforge/` and `/tab/f/` on purpose: a service worker in either scope would answer for it in a browser that started a tab forge. It is an open door for strangers, so it is limited by rate, not by count: 10 posts a minute per address (the `share` door in `src/http/strangers.ts`), taken before the body is read. Storage is bounded the other way: the forge keeps the newest 5000 links and the oldest go as a new one is made, so a link can stop opening once enough newer ones exist, and no one can fill the table and lock the door. It mints no account. Publishing is the one moment a person with no account becomes the visitor principal (#18216, `src/core/visitors.ts`): after the door and the body, the forge asks `may` for `visitor.make` (a refused credential is 403) and then `VISITOR_CAPS`, per visitor, per connection and per forge (429 past any), before anything is stored; once the link is made it is counted, and only then does the answer carry the signed `forge_maker` cookie. A spec that does not decode counts and mints nothing; `DNT: 1` or `Sec-GPC: 1` publishes and counts with no id kept; a signed-in person mints nothing. Reading or editing in the tab, and opening a link, mint nothing. There is no way to edit or delete a link yet. | |
| 22 | 22 | |
| 23 | 23 | The terminal's twin is the tab forge's palette entry (`src/tui/screens/tab.ts`): `tabLine()` says the same words (`TAB_LINK` in `src/tab/words.ts`). The terminal cannot hold a tab's app, so it has nothing to send. |
src/core/visitors.ts +3 −2
| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * A visitor principal (#18112): someone with no account the forge knows, minted only at the moment |
| 3 | 3 | * they make something (a note on an app's page), never on a |
| 4 | * read. Notes (`apps/feedback.ts`) and a game client link (#18189, | |
| 5 | * `web/pages/games_client_pack.ts`) mint today; the shared app (#18188) follows. The id rides its | |
| 4 | * read. Notes (`apps/feedback.ts`), a game client link (#18189, | |
| 5 | * `web/pages/games_client_pack.ts`) and publishing a tab app as a link (#18216, | |
| 6 | * `web/pages/tabforge-link.ts`) mint. The id rides its | |
| 6 | 7 | * own cookie, `forge_maker`, signed with a key derived for this purpose alone (HKDF, "forge visitor |
| 7 | 8 | * principal v1"), so the analytics cookie (`perf/visitor_id.ts`, `forge_visitor`) can never verify |
| 8 | 9 | * here and is never joined to it: the two share no id, no key and no table. `Sec-GPC: 1` or |
src/web/pages/tabforge-link.ts +23 −1
| @@ -4,10 +4,18 @@ | ||
| 4 | 4 | * it, and answers the link; GET /tabforge-link/:id draws the app, escaped, read-only, with no |
| 5 | 5 | * entries. The rest of the forge's floor applies as to any page: the same-origin gate, the security |
| 6 | 6 | * headers, the one 404 for an id that is not there. |
| 7 | * | |
| 8 | * Publishing is the one moment a person with no account becomes the visitor principal (#18216, | |
| 9 | * `core/visitors.ts`): `admitVisitor` asks `may` for `visitor.make` and the caps before anything is | |
| 10 | * stored, `countMake` counts the link once it is made, and only then does `forge_maker` ride the | |
| 11 | * answer. Opening a link, and everything in the tab, mints nothing. | |
| 7 | 12 | */ |
| 8 | 13 | import type { TabDb } from "../../tab/forge.ts"; |
| 9 | 14 | import { shareApp, sharedApp, sharedPage, SHARE_BODY_MAX, SHARE_PATH, isShareId } from "../../tab/share.ts"; |
| 15 | import { admitVisitor, countMake } from "../../core/visitors.ts"; | |
| 16 | import { secureFor } from "../../http/cookie_secure.ts"; | |
| 10 | 17 | import { clientBucket } from "../../http/peer.ts"; |
| 18 | import { loadKey } from "../../kernel/secret.ts"; | |
| 11 | 19 | import { takeDoor } from "../../http/strangers.ts"; |
| 12 | 20 | import type { Ctx } from "../../http/context.ts"; |
| 13 | 21 | import { ANSWER_HEADERS } from "../tabforge/routes.ts"; |
| @@ -30,8 +38,21 @@ export async function tabLinkMake(ctx: Ctx): Promise<Response> { | ||
| 30 | 38 | if (!verdict.allowed) return refusal(ctx, 429, `Too many tries from here; try again in ${verdict.retryAfter}s.`); |
| 31 | 39 | const form = await readForm(ctx, undefined, SHARE_BODY_MAX); |
| 32 | 40 | if (form instanceof Response) return form; |
| 33 | const made = shareApp(store(ctx), field(form, "app"), clientBucket(ctx.request), Date.now()); | |
| 41 | const client = clientBucket(ctx.request); | |
| 42 | // A signed-in person is already someone: they publish and mint nothing. | |
| 43 | const admitted = | |
| 44 | ctx.auth.user === undefined | |
| 45 | ? admitVisitor(ctx.app.db, () => loadKey(ctx.app.config.dataDir), { | |
| 46 | headers: ctx.request.headers, | |
| 47 | secure: secureFor(ctx.url, ctx.app.config.url), | |
| 48 | client, | |
| 49 | refused: ctx.auth.refused === true, | |
| 50 | }) | |
| 51 | : undefined; | |
| 52 | if (admitted !== undefined && !admitted.ok) return refusal(ctx, admitted.status, admitted.says); | |
| 53 | const made = shareApp(store(ctx), field(form, "app"), client, Date.now()); | |
| 34 | 54 | if (!made.ok) return refusal(ctx, made.status, made.why); |
| 55 | if (admitted !== undefined) countMake(ctx.app.db, admitted.visitorId, client); | |
| 35 | 56 | const link = `${ctx.url.origin}${SHARE_PATH}/${made.id}`; |
| 36 | 57 | const res = page({ |
| 37 | 58 | ctx, |
| @@ -41,6 +62,7 @@ export async function tabLinkMake(ctx: Ctx): Promise<Response> { | ||
| 41 | 62 | <p><a class="btn primary" href="${link}">${link}</a></p>`, |
| 42 | 63 | }, 201); |
| 43 | 64 | res.headers.set("cache-control", "no-store"); |
| 65 | if (admitted?.setCookie !== undefined) res.headers.append("set-cookie", admitted.setCookie); | |
| 44 | 66 | return res; |
| 45 | 67 | } |
| 46 | 68 |
test/cookie-flags.test.ts +1
| @@ -114,6 +114,7 @@ const WALKED: Record<string, number> = { | ||
| 114 | 114 | "src/apps/proxy.ts": 3, // app grant, app sign-out, toolbar dismissal |
| 115 | 115 | "src/apps/feedback.ts": 1, // a stranger's note on an app host: only the answer to a note made mints a visitor id |
| 116 | 116 | "src/web/pages/games_client_pack.ts": 1, // a linked game player mints the visitor id only on the link (#18189) |
| 117 | "src/web/pages/tabforge-link.ts": 1, // publishing a tab app mints the visitor id only once the link is made (#18216) | |
| 117 | 118 | "src/web/pages/passkeys.ts": 5, // import, passkey sign-in, passkey add/recovery-link sign-in, access-link sign-in (+1 mention) |
| 118 | 119 | "src/web/pages/site.ts": 5, // sessionCookie() itself and its uses: password sign-in/sign-up, logout; the theme cookie; the closing flash on a sign-in (#15619) |
| 119 | 120 | "src/web/pages/first-admin.ts": 1, // the first admin made by passkey |
new above
offline