Public: anyone can read this; the crew can change it.
An app made in the tab forge can be published as a read-only link on the forge, with no login #18219
Merged 11h 28m ago, live in production
scout/forge:scout/18215-an-app-made-in-the-tab-forge-can-be-publ → main 0 commits fork 3 threads · 3 unresolved
19 files
changed +324
−18
- docs/features/tabforge.md
- src/core/migration-pins/20261204120000-tab-shared-apps.pin
- src/core/migrations/20261204120000-tab-shared-apps.ts
- src/core/reserved.ts
- src/generated/marks.ts
- src/http/lazy_lists.ts
- src/http/marks/tabforge-link.json
- src/http/routes/discovery.ts
- src/http/strangers.ts
- src/tab/apps.ts
- src/tab/share.ts
- src/tab/words.ts
- src/web/pages/tabforge-link.ts
- test/budgets/unfixtured/tabforge-link-id.json
- test/forge-looks.test.ts
- test/no-polling.test.ts
- test/security-floor-routes.test.ts
- test/tab-share-door.test.ts
- test/tab-share.test.ts
docs/features/tabforge.md +8
| @@ -13,3 +13,11 @@ It needs a browser with service workers and the private file system. Without the | ||
| 13 | 13 | The page says, before anything else, where it lives: on this device, in this browser's own storage; it stops when the tab closes; others cannot reach it. Its one primary action opens the tab's home. It is two taps from making a forge: `/forges/new` carries a link, "Or try a forge in this tab", that leads to `/tabforge`. |
| 14 | 14 | |
| 15 | 15 | The page is `src/web/pages/tabforge.ts`; the words are `src/web/tabforge/words.ts`, shared with the terminal. The store itself exists only in a browser tab, which a terminal session cannot reach, so the terminal's twin is the new-forge screen (`src/tui/screens/newforge.ts`): its last row offers the tab forge with the same words and this forge's `/tabforge` address (hidden when the forge has no URL). The terminal's issue list (`src/tui/screens/issues.ts`) shows the forge's issues, not the tab's. |
| 16 | ||
| 17 | ## Get a link (#18215) | |
| 18 | ||
| 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 | ||
| 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. | |
| 22 | ||
| 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/reserved.ts +1
src/generated/marks.ts +15 −13
| @@ -204,19 +204,20 @@ import k199 from "../http/marks/support.json"; | ||
| 204 | 204 | import k200 from "../http/marks/sw.js.json"; |
| 205 | 205 | import k201 from "../http/marks/system.json"; |
| 206 | 206 | import k202 from "../http/marks/tab.json"; |
| 207 | import k203 from "../http/marks/tabforge.json"; | |
| 208 | import k204 from "../http/marks/talk.json"; | |
| 209 | import k205 from "../http/marks/tell.json"; | |
| 210 | import k206 from "../http/marks/templates.json"; | |
| 211 | import k207 from "../http/marks/templates.json.json"; | |
| 212 | import k208 from "../http/marks/terms.json"; | |
| 213 | import k209 from "../http/marks/theme.json"; | |
| 214 | import k210 from "../http/marks/toolbar-lab.js.json"; | |
| 215 | import k211 from "../http/marks/toolbar-lab.json"; | |
| 216 | import k212 from "../http/marks/traces.json"; | |
| 217 | import k213 from "../http/marks/verify.json"; | |
| 218 | import k214 from "../http/marks/welcome.json"; | |
| 219 | import k215 from "../http/marks/well-known.json"; | |
| 207 | import k203 from "../http/marks/tabforge-link.json"; | |
| 208 | import k204 from "../http/marks/tabforge.json"; | |
| 209 | import k205 from "../http/marks/talk.json"; | |
| 210 | import k206 from "../http/marks/tell.json"; | |
| 211 | import k207 from "../http/marks/templates.json"; | |
| 212 | import k208 from "../http/marks/templates.json.json"; | |
| 213 | import k209 from "../http/marks/terms.json"; | |
| 214 | import k210 from "../http/marks/theme.json"; | |
| 215 | import k211 from "../http/marks/toolbar-lab.js.json"; | |
| 216 | import k212 from "../http/marks/toolbar-lab.json"; | |
| 217 | import k213 from "../http/marks/traces.json"; | |
| 218 | import k214 from "../http/marks/verify.json"; | |
| 219 | import k215 from "../http/marks/welcome.json"; | |
| 220 | import k216 from "../http/marks/well-known.json"; | |
| 220 | 221 | |
| 221 | 222 | /** Each file of `http/marks/`, parsed, in name order. */ |
| 222 | 223 | export const MARK_FILES: readonly unknown[] = [ |
| @@ -436,4 +437,5 @@ export const MARK_FILES: readonly unknown[] = [ | ||
| 436 | 437 | k213, |
| 437 | 438 | k214, |
| 438 | 439 | k215, |
| 440 | k216, | |
| 439 | 441 | ]; |
src/http/lazy_lists.ts +2
src/http/marks/tabforge-link.json added +4
src/http/routes/discovery.ts +5
| @@ -14,6 +14,7 @@ import { machineTermAsset, ghosttyWasmAsset, wasmResponse } from "../../web/mach | ||
| 14 | 14 | import { openSearch } from "../../web/opensearch.ts"; |
| 15 | 15 | import { agentsPage } from "../../web/pages/agents.ts"; |
| 16 | 16 | import { tabforgePage } from "../../web/pages/tabforge.ts"; |
| 17 | import { tabLinkMake, tabLinkOpen } from "../../web/pages/tabforge-link.ts"; | |
| 17 | 18 | import { offlinePage } from "../../web/pages/offline.ts"; |
| 18 | 19 | import { tabPage } from "../../web/pages/tab.ts"; |
| 19 | 20 | import { tabFile, tabVendor } from "../../web/tab-asset.ts"; |
| @@ -134,4 +135,8 @@ export function discoveryRoutes(router: Router<Handler>): void { | ||
| 134 | 135 | router.add("GET", "/tab/:name", (ctx) => tabFile(ctx.request, ctx.params.name!)); |
| 135 | 136 | router.add("GET", "/tabforge/sw.js", () => tabforgeWorkerResponse()); // the tab forge's own scope (#17275) |
| 136 | 137 | router.add("GET", "/tabforge", tabforgePage); // outside that scope: the page that registers it |
| 138 | // An app from a tab as a read-only link (#18215). Outside the tab forge's `/tabforge/` and | |
| 139 | // `/tab/f/` scopes, so no worker answers it. | |
| 140 | router.add("POST", "/tabforge-link", tabLinkMake); | |
| 141 | router.add("GET", "/tabforge-link/:id", tabLinkOpen); | |
| 137 | 142 | } |
src/http/strangers.ts +3 −3
| @@ -23,7 +23,7 @@ import { transferGate } from "../git/env.ts"; | ||
| 23 | 23 | import { bucketOf, clientBucket } from "./peer.ts"; |
| 24 | 24 | |
| 25 | 25 | /** A door a stranger is counted at, each with its own minute. */ |
| 26 | export type Door = "api" | "git" | "code" | "plan" | "pay"; | |
| 26 | export type Door = "api" | "git" | "code" | "plan" | "pay" | "share"; | |
| 27 | 27 | |
| 28 | 28 | export interface StrangerLimits { |
| 29 | 29 | /** Requests per minute through each door, per client address. */ |
| @@ -72,8 +72,8 @@ export interface StrangerLimits { | ||
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | export const STRANGER_LIMITS: StrangerLimits = { |
| 75 | perAddress: { api: 600, git: 60, code: 10, plan: 10, pay: 5 }, | |
| 76 | forge: { api: 6000, git: 600, code: 60, plan: 60, pay: 60 }, | |
| 75 | perAddress: { api: 600, git: 60, code: 10, plan: 10, pay: 5, share: 10 }, | |
| 76 | forge: { api: 6000, git: 600, code: 60, plan: 60, pay: 60, share: 120 }, | |
| 77 | 77 | transfersPerAddress: 4, |
| 78 | 78 | transferShare: 0.5, |
| 79 | 79 | transferTimeoutMs: 7_200_000, |
src/tab/apps.ts +3 −1
| @@ -7,7 +7,9 @@ import { esc } from "./escape.ts"; | ||
| 7 | 7 | import { settle } from "./fill.ts"; |
| 8 | 8 | import type { TabDb, TabReply, TabRequest } from "./forge.ts"; |
| 9 | 9 | import { ROOT, renderApp, type Rec } from "./render.ts"; |
| 10 | import { linkForm } from "./share.ts"; | |
| 10 | 11 | import { shell } from "./shell.ts"; |
| 12 | import { TAB_LINK, TAB_LINK_LABEL } from "./words.ts"; | |
| 11 | 13 | import { decodeApp, entryText, SPEC_VERSION, type BlockApp } from "./blocks.ts"; |
| 12 | 14 | |
| 13 | 15 | export const SAY_MAX = 300; |
| @@ -93,7 +95,7 @@ export function handleApps(db: TabDb, req: TabRequest, path: string, now: number | ||
| 93 | 95 | if (req.method === "GET" && parts.length === 1) |
| 94 | 96 | return found === null |
| 95 | 97 | ? shell(title, `<h1>${esc(title)}</h1><p>This app's spec cannot be read, so it cannot be drawn. It can still be removed.</p>${removeForm(id, title)}`) |
| 96 | : shell(found.app.title, `${renderApp(found.app, { appId: id, records: records(db, id), today: dayOf(now) })}<p><a href="${ROOT}/apps/${id}/source">How this app was made</a></p>${removeForm(id, title)}`, 200, false); | |
| 98 | : shell(found.app.title, `${renderApp(found.app, { appId: id, records: records(db, id), today: dayOf(now) })}<p><a href="${ROOT}/apps/${id}/source">How this app was made</a></p><p class="muted">${esc(TAB_LINK)}</p>${linkForm(found.app, TAB_LINK_LABEL)}${removeForm(id, title)}`, 200, false); | |
| 97 | 99 | if (req.method === "GET" && parts[1] === "source" && parts.length === 2) return found === null ? notFound() : shell(`${found.app.title}: why`, source(found)); |
| 98 | 100 | if (req.method !== "POST") return shell("Not allowed", "<p>That is not something this forge does.</p>", 405); |
| 99 | 101 | if (parts[1] === "delete" && parts.length === 2) { |
src/tab/words.ts +8 −1
| @@ -18,6 +18,13 @@ export const TAB_LEFT_OUT = "No git, shell or installs here: those need a real L | ||
| 18 | 18 | /** How an app leaves and enters: one file, checked on the way in. */ |
| 19 | 19 | export const TAB_MOVE = "An app is one JSON file: download it from the forge's home (with its issues or without) and choose it (or paste it) in another tab forge, which refuses a file that does not fit."; |
| 20 | 20 | |
| 21 | /** | |
| 22 | * The link an app's page offers beside the file: the button's label and what it does, said the same | |
| 23 | * everywhere. | |
| 24 | */ | |
| 25 | export const TAB_LINK_LABEL = "Get a link"; | |
| 26 | export const TAB_LINK = "Get a link: send an app to the forge and get one read-only address that opens it on any device, with no login. Only the app goes, never its entries; anyone with the address can read it, so share it only where you mean to."; | |
| 27 | ||
| 21 | 28 | /** |
| 22 | 29 | * The optional model, said before anything is downloaded. It only fills the app's spec (a title, a |
| 23 | 30 | * kind and a few words, checked against a schema); the compiler writes the spec when there is no |
| @@ -29,4 +36,4 @@ export const TAB_MODEL: readonly string[] = [ | ||
| 29 | 36 | ]; |
| 30 | 37 | |
| 31 | 38 | /** The terminal's one sentence: the facts and where the page is. */ |
| 32 | export const tabLine = (): string => `${TAB_FACTS.join(" ")} ${TAB_LEFT_OUT} ${TAB_MOVE} ${TAB_MODEL.join(" ")} Open /tab in a browser to start it and to make an app from a sentence.`; | |
| 39 | export const tabLine = (): string => `${TAB_FACTS.join(" ")} ${TAB_LEFT_OUT} ${TAB_MOVE} ${TAB_LINK} ${TAB_MODEL.join(" ")} Open /tab in a browser to start it and to make an app from a sentence.`; |
src/web/pages/tabforge-link.ts added +52
| @@ -0,0 +1,52 @@ | ||
| 1 | /** | |
| 2 | * An app made in a browser tab, as one read-only link (#18215), for a person with no account: | |
| 3 | * POST /tabforge-link takes the app's JSON (form field `app`), has `tab/share.ts` validate and keep | |
| 4 | * it, and answers the link; GET /tabforge-link/:id draws the app, escaped, read-only, with no | |
| 5 | * entries. The rest of the forge's floor applies as to any page: the same-origin gate, the security | |
| 6 | * headers, the one 404 for an id that is not there. | |
| 7 | */ | |
| 8 | import type { TabDb } from "../../tab/forge.ts"; | |
| 9 | import { shareApp, sharedApp, sharedPage, SHARE_BODY_MAX, SHARE_PATH, isShareId } from "../../tab/share.ts"; | |
| 10 | import { clientBucket } from "../../http/peer.ts"; | |
| 11 | import { takeDoor } from "../../http/strangers.ts"; | |
| 12 | import type { Ctx } from "../../http/context.ts"; | |
| 13 | import { ANSWER_HEADERS } from "../tabforge/routes.ts"; | |
| 14 | import { notFoundPage, pageHead } from "../chrome.ts"; | |
| 15 | import { field, readForm } from "../form.ts"; | |
| 16 | import { html } from "../html.ts"; | |
| 17 | import { page } from "../layout.ts"; | |
| 18 | ||
| 19 | /** The forge's database as the two-function store `tab/share.ts` asks for. */ | |
| 20 | const store = (ctx: Ctx): TabDb => ({ | |
| 21 | run: (sql, bind = []) => void ctx.app.db.query(sql).run(...bind), | |
| 22 | all: (sql, bind = []) => ctx.app.db.query(sql).all(...bind) as Record<string, string | number>[], | |
| 23 | }); | |
| 24 | ||
| 25 | const refusal = (ctx: Ctx, status: number, why: string): Response => | |
| 26 | page({ ctx, title: "No link made", body: html`${pageHead(html`No link made`)}<p role="alert">${why}</p><p><a href="/tab">Back to the tab forge</a></p>` }, status); | |
| 27 | ||
| 28 | export async function tabLinkMake(ctx: Ctx): Promise<Response> { | |
| 29 | const verdict = takeDoor(ctx.app, "share", ctx.request); | |
| 30 | if (!verdict.allowed) return refusal(ctx, 429, `Too many tries from here; try again in ${verdict.retryAfter}s.`); | |
| 31 | const form = await readForm(ctx, undefined, SHARE_BODY_MAX); | |
| 32 | if (form instanceof Response) return form; | |
| 33 | const made = shareApp(store(ctx), field(form, "app"), clientBucket(ctx.request), Date.now()); | |
| 34 | if (!made.ok) return refusal(ctx, made.status, made.why); | |
| 35 | const link = `${ctx.url.origin}${SHARE_PATH}/${made.id}`; | |
| 36 | const res = page({ | |
| 37 | ctx, | |
| 38 | title: "Your link", | |
| 39 | body: html`${pageHead(html`Your link`)} | |
| 40 | <p>Anyone with this address can read the app, on any device, with no login. Only the app is here, never its entries.</p> | |
| 41 | <p><a class="btn primary" href="${link}">${link}</a></p>`, | |
| 42 | }, 201); | |
| 43 | res.headers.set("cache-control", "no-store"); | |
| 44 | return res; | |
| 45 | } | |
| 46 | ||
| 47 | export function tabLinkOpen(ctx: Ctx): Response { | |
| 48 | const id = ctx.params.id ?? ""; | |
| 49 | const app = isShareId(id) ? sharedApp(store(ctx), id) : null; | |
| 50 | if (app === null) return notFoundPage(ctx); | |
| 51 | return new Response(sharedPage(app), { headers: { ...ANSWER_HEADERS, "content-type": "text/html; charset=utf-8", "cache-control": "no-cache" } }); | |
| 52 | } |
test/budgets/unfixtured/tabforge-link-id.json added +4
test/forge-looks.test.ts +1
| @@ -32,6 +32,7 @@ const NOT_A_PAGE: Record<string, string> = { | ||
| 32 | 32 | "/next": "no picture: not in app.looks (its 32 slots are full); the page is covered by test/next-all.test.ts", |
| 33 | 33 | "/pricing": "no picture: not in app.looks; the page is covered by test/pricing-order.test.ts", |
| 34 | 34 | "/tabforge": "no picture: not in app.looks (its 32 slots are full); the page is covered by test/tabforge-page.test.ts", |
| 35 | "/tabforge-link": "no picture: not in app.looks (its 32 slots are full); a POST that stores an app and answers a link, and /tabforge-link/<id> needs a stored app; covered by test/tab-share.test.ts", | |
| 35 | 36 | "/archive": "no picture: not in app.looks (its 32 slots are full); the page is covered by test/archive-page.test.ts, with a 390 px measure, and test/apps-archived.test.ts", |
| 36 | 37 | "/templates": "no picture: not in app.looks; the page is covered by test/templates-page.test.ts", |
| 37 | 38 | "/traces": "no picture: not in app.looks (its 32 slots are full); the page is covered by test/traces-list.test.ts", |
test/no-polling.test.ts +1
| @@ -306,6 +306,7 @@ const NOT_WALKED: Record<string, string> = { | ||
| 306 | 306 | "/talk/dev/:token": "a frame proxied from a running dev cell, not a page; the seed starts none", |
| 307 | 307 | "/talk/dev/:token/*path": "a file proxied from a running dev cell, not a page; the seed starts none", |
| 308 | 308 | "/infra/end/:act/*path": "the plan of a stop or delete, a page for a cloud resource the seed does not have; the action word is not in the seed", |
| 309 | "/tabforge-link/:id": "a shared tab-forge app named by a random id the seed does not hold (test/tab-share.test.ts covers it)", | |
| 309 | 310 | "/tab/v/:hash/:file": "a content-hashed browser-tab bundle file, JS or wasm, not a page; the hash is one the seed cannot guess", |
| 310 | 311 | "/edge/config/:file": "a published config file for the edge, JSON or a key, not a page; the seed publishes none", |
| 311 | 312 | "/:owner/-/teams/:team": "needs an organization and a team", |
test/security-floor-routes.test.ts +1
| @@ -70,6 +70,7 @@ const REPORT = "needs a report an outsider filed; the seed has none"; | ||
| 70 | 70 | const SHOT = "needs a pin with a picture kept by refs/shots; the seed pins nothing"; |
| 71 | 71 | const CART = "the seed pins no build with a cart (test/build-cart.test.ts covers its headers)"; |
| 72 | 72 | const UNSEEDED: Record<string, string> = { |
| 73 | "/tabforge-link/:id": "a shared tab-forge app named by a random id the seed does not hold (test/tab-share.test.ts covers it)", | |
| 73 | 74 | "/tab/v/:hash/:file": "a vendored file of the browser-tab forge, named by its content hash, which the seed does not hold (test/tab.test.ts covers it)", |
| 74 | 75 | "/infra/end/:act/*path": "the plan of a stop or delete for a cloud resource, which the seed does not have (test/cloud-end.test.ts covers it)", |
| 75 | 76 | "/games/:box": "a game box, which the seed does not make (test/games.test.ts covers it)", |
new above
offline
Non-blocking: the per-connection count this comment describes is gone, so
bucketand its index serve nothing now. Remove them (and re-pin) or say what they are kept for.