Public: anyone can read this; the crew can change it.
A tab-forge read-only link can be revoked by the person who made it #18402
Merged 2h 23m ago, live in production
scout/forge:scout/18398-a-tab-forge-read-only-link-can-be-revoke → main 0 commits fork 4 threads · 4 unresolved
12 files
changed +274
−18
- docs/features/tabforge.md
- src/core/migration-pins/20261206090000-tab-shared-revoke.pin
- src/core/migrations/20261206090000-tab-shared-revoke.ts
- src/http/lazy_lists.ts
- src/http/routes/discovery.ts
- src/http/strangers.ts
- src/tab/apps.ts
- src/tab/revoke_key.ts
- src/tab/share.ts
- src/tab/words.ts
- src/web/pages/tabforge-link.ts
- test/tab-share-revoke.test.ts
docs/features/tabforge.md +7 −1
| @@ -18,6 +18,12 @@ 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. 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. | |
| 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. A link cannot be edited. | |
| 22 | ||
| 23 | ## Stop sharing (#18398) | |
| 24 | ||
| 25 | Making a link also makes a revoke key (192 random bits), shown once on the page that answers and never in the link. Only its SHA-256 is stored, in `tab_shared.key_hash` (`src/tab/revoke_key.ts`); the column is nullable, so a link made before keys existed has no hash, stays openable and cannot be stopped. The answer page offers **Keep the key in my tab**, a form to the tab forge's own page for the app (`/tab/f/apps/<n>/links`), which stores the link and key in the tab's `kept_link` table. The app's page then lists its links under "Links you made", each with **Stop sharing**: a POST to `/tabforge-link/<id>/revoke` with the key (same-origin checked, its own `revoke` door applies, so stopping links is not throttled by making them). The list's form also sends the app's number, so the answer (stopped, or no longer there) offers **Remove it from my tab's list**, which drops the kept row; the list never keeps a dead link. The right key deletes the row, so the link answers the forge's one 404; a wrong or missing key, or a row with no hash, changes nothing and says "Nothing changed" (403); keys are compared as hashes in constant time. Clearing the site's data loses the keys, and the page says so. The key is not kept unless the person presses the button: with script off or no tab forge they copy it from the page. | |
| 26 | ||
| 27 | The terminal says the same words (`TAB_REVOKE` in `src/tab/words.ts`, part of `tabLine()`); a terminal holds no tab's keys, so it has nothing to stop. | |
| 22 | 28 | |
| 23 | 29 | 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/http/lazy_lists.ts +1
src/http/routes/discovery.ts +2 −1
| @@ -14,7 +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, tabMoveIn } from "../../web/pages/tabforge-link.ts"; | |
| 17 | import { tabLinkMake, tabLinkOpen, tabLinkRevoke, tabMoveIn } from "../../web/pages/tabforge-link.ts"; | |
| 18 | 18 | import { offlinePage } from "../../web/pages/offline.ts"; |
| 19 | 19 | import { tabPage } from "../../web/pages/tab.ts"; |
| 20 | 20 | import { tabFile, tabVendor } from "../../web/tab-asset.ts"; |
| @@ -139,5 +139,6 @@ export function discoveryRoutes(router: Router<Handler>): void { | ||
| 139 | 139 | // `/tab/f/` scopes, so no worker answers it. |
| 140 | 140 | router.add("POST", "/tabforge-link", tabLinkMake); |
| 141 | 141 | router.add("GET", "/tabforge-link/:id", tabLinkOpen); |
| 142 | router.add("POST", "/tabforge-link/:id/revoke", tabLinkRevoke); | |
| 142 | 143 | router.add("POST", "/tabforge-move", tabMoveIn); |
| 143 | 144 | } |
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" | "share"; | |
| 26 | export type Door = "api" | "git" | "code" | "plan" | "pay" | "share" | "revoke"; | |
| 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, share: 10 }, | |
| 76 | forge: { api: 6000, git: 600, code: 60, plan: 60, pay: 60, share: 120 }, | |
| 75 | perAddress: { api: 600, git: 60, code: 10, plan: 10, pay: 5, share: 10, revoke: 10 }, | |
| 76 | forge: { api: 6000, git: 600, code: 60, plan: 60, pay: 60, share: 120, revoke: 60 }, | |
| 77 | 77 | transfersPerAddress: 4, |
| 78 | 78 | transferShare: 0.5, |
| 79 | 79 | transferTimeoutMs: 7_200_000, |
src/tab/apps.ts +27 −3
| @@ -8,9 +8,9 @@ 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 | 10 | import { fileName, openFile, saveFile, FILE_MAX } from "./file.ts"; |
| 11 | import { linkForm, MOVE_PATH } from "./share.ts"; | |
| 11 | import { isShareId, keptLinkRow, linkForm, MOVE_PATH } from "./share.ts"; | |
| 12 | 12 | import { shell } from "./shell.ts"; |
| 13 | import { TAB_KEEP, TAB_KEEP_LABEL, TAB_LINK, TAB_LINK_LABEL } from "./words.ts"; | |
| 13 | import { TAB_KEEP, TAB_KEEP_LABEL, TAB_LINK, TAB_LINK_LABEL, TAB_REVOKE } from "./words.ts"; | |
| 14 | 14 | import { decodeApp, entryText, SPEC_VERSION, type BlockApp } from "./blocks.ts"; |
| 15 | 15 | |
| 16 | 16 | export const SAY_MAX = 300; |
| @@ -20,6 +20,7 @@ export function migrateApps(db: TabDb): void { | ||
| 20 | 20 | db.run("CREATE TABLE IF NOT EXISTS made (id INTEGER PRIMARY KEY, title TEXT NOT NULL, spec TEXT NOT NULL, why TEXT NOT NULL, created INTEGER NOT NULL)"); |
| 21 | 21 | db.run("CREATE TABLE IF NOT EXISTS rec (id INTEGER PRIMARY KEY, app INTEGER NOT NULL, block INTEGER NOT NULL, text TEXT NOT NULL, n REAL NOT NULL, col INTEGER NOT NULL, day TEXT NOT NULL, created INTEGER NOT NULL)"); |
| 22 | 22 | db.run("CREATE INDEX IF NOT EXISTS rec_app ON rec (app)"); |
| 23 | db.run("CREATE TABLE IF NOT EXISTS kept_link (link TEXT PRIMARY KEY, app INTEGER NOT NULL, key TEXT NOT NULL, created INTEGER NOT NULL)"); | |
| 23 | 24 | } |
| 24 | 25 | |
| 25 | 26 | /** The device's local day, `YYYY-MM-DD`. */ |
| @@ -67,6 +68,15 @@ export function appsHome(db: TabDb): string { | ||
| 67 | 68 | const records = (db: TabDb, app: number): Rec[] => |
| 68 | 69 | db.all("SELECT id, block, text, n, col, day FROM rec WHERE app = ? ORDER BY id", [app]).map((r) => ({ id: Number(r.id), block: Number(r.block), text: String(r.text), n: Number(r.n), col: Number(r.col), day: String(r.day) })); |
| 69 | 70 | |
| 71 | /** | |
| 72 | * The links this tab made for app `id`, with the keys that take them back (never sent anywhere | |
| 73 | * else). | |
| 74 | */ | |
| 75 | const keptLinks = (db: TabDb, id: number): string => { | |
| 76 | const rows = db.all("SELECT link, key FROM kept_link WHERE app = ? ORDER BY created DESC", [id]); | |
| 77 | return rows.length === 0 ? "" : `<h2>Links you made</h2><p class="muted">${esc(TAB_REVOKE)}</p><ul class="items">${rows.map((r) => keptLinkRow(String(r.link), String(r.key), id)).join("")}</ul>`; | |
| 78 | }; | |
| 79 | ||
| 70 | 80 | const notFound = (): TabReply => shell("Not found", "<p>No such app.</p>", 404); |
| 71 | 81 | const back = (id: number): TabReply => ({ status: 303, html: "", location: `${ROOT}/apps/${id}` }); |
| 72 | 82 | const refuse = (why: string): TabReply => shell("Not saved", `<p>${esc(why)}</p>`, 422); |
| @@ -121,16 +131,30 @@ export function handleApps(db: TabDb, req: TabRequest, path: string, now: number | ||
| 121 | 131 | if (req.method === "GET" && parts.length === 1) |
| 122 | 132 | return found === null |
| 123 | 133 | ? 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)}`) |
| 124 | : 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)}${saveLinks(id)}<p class="muted">${esc(TAB_KEEP)}</p>${linkForm(found.app, TAB_KEEP_LABEL, MOVE_PATH)}${removeForm(id, title)}`, 200, false); | |
| 134 | : 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, undefined, id)}${keptLinks(db, id)}${saveLinks(id)}<p class="muted">${esc(TAB_KEEP)}</p>${linkForm(found.app, TAB_KEEP_LABEL, MOVE_PATH)}${removeForm(id, title)}`, 200, false); | |
| 125 | 135 | if (req.method === "GET" && parts[1] === "file" && parts.length === 2 && found !== null) { |
| 126 | 136 | const withRecords = ["1", "true"].includes(new URLSearchParams(req.query ?? "").get("records") ?? ""); |
| 127 | 137 | return { status: 200, html: saveFile(found.app, withRecords ? records(db, id) : undefined), file: { type: "application/json", name: fileName(found.app) } }; |
| 128 | 138 | } |
| 129 | 139 | if (req.method === "GET" && parts[1] === "source" && parts.length === 2) return found === null ? notFound() : shell(`${found.app.title}: why`, source(found)); |
| 130 | 140 | if (req.method !== "POST") return shell("Not allowed", "<p>That is not something this forge does.</p>", 405); |
| 141 | if (parts[1] === "links" && parts.length === 2) { | |
| 142 | const forget = req.form.forget ?? ""; | |
| 143 | if (forget !== "") { | |
| 144 | if (!isShareId(forget)) return refuse("That link does not look right. Nothing was removed."); | |
| 145 | db.run("DELETE FROM kept_link WHERE link = ? AND app = ?", [forget, id]); | |
| 146 | return back(id); | |
| 147 | } | |
| 148 | const link = req.form.link ?? ""; | |
| 149 | const key = req.form.key ?? ""; | |
| 150 | if (!isShareId(link) || !/^[A-Za-z0-9_-]{1,64}$/.test(key)) return refuse("That link or key does not look right. Nothing was kept."); | |
| 151 | db.run("INSERT OR REPLACE INTO kept_link (link, app, key, created) VALUES (?, ?, ?, ?)", [link, id, key, now]); | |
| 152 | return back(id); | |
| 153 | } | |
| 131 | 154 | if (parts[1] === "delete" && parts.length === 2) { |
| 132 | 155 | if ((req.form.confirm ?? "").trim() !== title.trim()) return refuse("Type the app's title exactly to remove it and its entries. Nothing was removed."); |
| 133 | 156 | db.run("DELETE FROM rec WHERE app = ?", [id]); |
| 157 | db.run("DELETE FROM kept_link WHERE app = ?", [id]); | |
| 134 | 158 | db.run("DELETE FROM made WHERE id = ?", [id]); |
| 135 | 159 | return { status: 303, html: "", location: `${ROOT}/` }; |
| 136 | 160 | } |
src/tab/revoke_key.ts added +32
| @@ -0,0 +1,32 @@ | ||
| 1 | /** | |
| 2 | * The revoke key of a read-only link (#18398): made once, shown once, never in the link. Only its | |
| 3 | * SHA-256 is stored in `tab_shared.key_hash`; a presented key is compared in constant time. Server | |
| 4 | * side only (it uses node:crypto); the tab itself keeps the key as plain text it was shown. | |
| 5 | */ | |
| 6 | import { createHash, randomBytes, timingSafeEqual } from "node:crypto"; | |
| 7 | import type { TabDb } from "./forge.ts"; | |
| 8 | import { isShareId } from "./share.ts"; | |
| 9 | ||
| 10 | const hashOf = (key: string): Buffer => createHash("sha256").update(key).digest(); | |
| 11 | ||
| 12 | /** A new key (192 random bits) and the hash to store. */ | |
| 13 | export function newKey(): { readonly key: string; readonly hash: string } { | |
| 14 | const key = randomBytes(24).toString("base64url"); | |
| 15 | return { key, hash: hashOf(key).toString("hex") }; | |
| 16 | } | |
| 17 | ||
| 18 | export type Revoked = "gone" | "wrong" | "unknown"; | |
| 19 | ||
| 20 | /** | |
| 21 | * Take the link back when `key` is the one it was made with. A row with no hash (made before keys) | |
| 22 | * cannot be revoked and says "wrong"; an id that is not there is "unknown" (the forge's 404). | |
| 23 | */ | |
| 24 | export function revokeShared(db: TabDb, id: string, key: string): Revoked { | |
| 25 | if (!isShareId(id)) return "unknown"; | |
| 26 | const row = db.all("SELECT key_hash FROM tab_shared WHERE id = ?", [id])[0]; | |
| 27 | if (row === undefined) return "unknown"; | |
| 28 | const stored = typeof row.key_hash === "string" && /^[0-9a-f]{64}$/.test(row.key_hash) ? Buffer.from(row.key_hash, "hex") : null; | |
| 29 | if (stored === null || key === "" || key.length > 200 || !timingSafeEqual(stored, hashOf(key))) return "wrong"; | |
| 30 | db.run("DELETE FROM tab_shared WHERE id = ?", [id]); | |
| 31 | return "gone"; | |
| 32 | } |
src/tab/words.ts +7 −1
| @@ -25,6 +25,12 @@ export const TAB_MOVE = "An app is one JSON file: download it from the forge's h | ||
| 25 | 25 | export const TAB_LINK_LABEL = "Get a link"; |
| 26 | 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 | 27 | |
| 28 | /** | |
| 29 | * Taking a link back (#18398): the key made with the link is shown once and kept in this tab, never | |
| 30 | * in the link; the app's page lists the links this tab made, each with Stop sharing. | |
| 31 | */ | |
| 32 | export const TAB_REVOKE = "Stop sharing: each link made here has a key, shown once and kept in this tab (never in the link). Stop sharing with the right key deletes the link, which then opens nothing; a wrong key changes nothing. Clearing this site's data loses the keys, and links made before keys existed cannot be stopped."; | |
| 33 | ||
| 28 | 34 | /** |
| 29 | 35 | * The move an app's page offers (#18114): the app goes to this forge held by this browser's |
| 30 | 36 | * visitor, and signing in or up offers it to the account. The Apple app's on-device mode sends the |
| @@ -50,4 +56,4 @@ export const TAB_MODEL: readonly string[] = [ | ||
| 50 | 56 | export const TAB_WHOLE = "Once started it fills the tab. Its What works page names every page of the hosted forge and says whether it works here, works differently or cannot work in a tab (and why); its Runners page says what a tab can and cannot run. It reopens where you were after a reload or a new tab, and asks the browser to keep its storage."; |
| 51 | 57 | |
| 52 | 58 | /** The terminal's one sentence: the facts and where the page is. */ |
| 53 | export const tabLine = (): string => `${TAB_FACTS.join(" ")} ${TAB_LEFT_OUT} ${TAB_MOVE} ${TAB_LINK} ${TAB_KEEP} ${TAB_MODEL.join(" ")} ${TAB_WHOLE} Open /tab in a browser to start it and to make an app from a sentence.`; | |
| 59 | export const tabLine = (): string => `${TAB_FACTS.join(" ")} ${TAB_LEFT_OUT} ${TAB_MOVE} ${TAB_LINK} ${TAB_REVOKE} ${TAB_KEEP} ${TAB_MODEL.join(" ")} ${TAB_WHOLE} Open /tab in a browser to start it and to make an app from a sentence.`; |
src/web/pages/tabforge-link.ts +37 −4
| @@ -16,7 +16,8 @@ | ||
| 16 | 16 | */ |
| 17 | 17 | import type { TabDb } from "../../tab/forge.ts"; |
| 18 | 18 | import { decodeApp, LIMITS } from "../../tab/blocks.ts"; |
| 19 | import { shareApp, sharedApp, sharedPage, SHARE_BODY_MAX, SHARE_PATH, isShareId } from "../../tab/share.ts"; | |
| 19 | import { forgetKeyForm, keepKeyForm, shareApp, sharedApp, sharedPage, SHARE_BODY_MAX, SHARE_PATH, isShareId } from "../../tab/share.ts"; | |
| 20 | import { newKey, revokeShared } from "../../tab/revoke_key.ts"; | |
| 20 | 21 | import { keepMoved } from "../../core/visitor_bring.ts"; |
| 21 | 22 | import { admitVisitor, countMake } from "../../core/visitors.ts"; |
| 22 | 23 | import { secureFor } from "../../http/cookie_secure.ts"; |
| @@ -27,7 +28,7 @@ import type { Ctx } from "../../http/context.ts"; | ||
| 27 | 28 | import { ANSWER_HEADERS } from "../tabforge/routes.ts"; |
| 28 | 29 | import { notFoundPage, pageHead } from "../chrome.ts"; |
| 29 | 30 | import { field, readForm } from "../form.ts"; |
| 30 | import { html } from "../html.ts"; | |
| 31 | import { html, raw } from "../html.ts"; | |
| 31 | 32 | import { page } from "../layout.ts"; |
| 32 | 33 | |
| 33 | 34 | /** The forge's database as the two-function store `tab/share.ts` asks for. */ |
| @@ -56,22 +57,54 @@ export async function tabLinkMake(ctx: Ctx): Promise<Response> { | ||
| 56 | 57 | }) |
| 57 | 58 | : undefined; |
| 58 | 59 | if (admitted !== undefined && !admitted.ok) return refusal(ctx, admitted.status, admitted.says); |
| 59 | const made = shareApp(store(ctx), field(form, "app"), client, Date.now()); | |
| 60 | const secret = newKey(); | |
| 61 | const made = shareApp(store(ctx), field(form, "app"), client, Date.now(), secret.hash); | |
| 60 | 62 | if (!made.ok) return refusal(ctx, made.status, made.why); |
| 61 | 63 | if (admitted !== undefined) countMake(ctx.app.db, admitted.visitorId, client); |
| 62 | 64 | const link = `${ctx.url.origin}${SHARE_PATH}/${made.id}`; |
| 65 | const from = /^\d{1,9}$/.test(field(form, "from")) ? Number(field(form, "from")) : null; | |
| 63 | 66 | const res = page({ |
| 64 | 67 | ctx, |
| 65 | 68 | title: "Your link", |
| 66 | 69 | body: html`${pageHead(html`Your link`)} |
| 67 | 70 | <p>Anyone with this address can read the app, on any device, with no login. Only the app is here, never its entries.</p> |
| 68 | <p><a class="btn primary" href="${link}">${link}</a></p>`, | |
| 71 | <p><a class="btn primary" href="${link}">${link}</a></p> | |
Principle 1: |
||
| 72 | <h2>Your key to stop sharing</h2> | |
| 73 | <p>Shown once, not in the link: the only way to take this link back.</p> | |
| 74 | <p><code>${secret.key}</code></p> | |
| 75 | ${from === null ? html`<p>Keep it somewhere safe.</p>` : html`<p>Keep it in the tab you made the app in, so its page can list this link with Stop sharing.</p>${raw(keepKeyForm(from, made.id, secret.key))}`}`, | |
| 69 | 76 | }, 201); |
| 70 | 77 | res.headers.set("cache-control", "no-store"); |
| 71 | 78 | if (admitted?.setCookie !== undefined) res.headers.append("set-cookie", admitted.setCookie); |
| 72 | 79 | return res; |
| 73 | 80 | } |
| 74 | 81 | |
| 82 | /** | |
| 83 | * Take a link back: the maker's key deletes the row; a wrong or missing key changes nothing and | |
| 84 | * says so. | |
| 85 | */ | |
| 86 | export async function tabLinkRevoke(ctx: Ctx): Promise<Response> { | |
| 87 | const verdict = takeDoor(ctx.app, "revoke", ctx.request); | |
| 88 | if (!verdict.allowed) return refusal(ctx, 429, `Too many tries from here; try again in ${verdict.retryAfter}s.`, "Not stopped"); | |
| 89 | const form = await readForm(ctx, undefined, 1024); | |
| 90 | if (form instanceof Response) return form; | |
| 91 | const done = revokeShared(store(ctx), ctx.params.id ?? "", field(form, "key")); | |
| 92 | const id = ctx.params.id ?? ""; | |
| 93 | const from = /^\d{1,9}$/.test(field(form, "from")) ? Number(field(form, "from")) : null; | |
| 94 | // The tab's list must not keep a link that is gone: its page offers to forget the row. | |
| 95 | const forget = from === null || !isShareId(id) ? "" : forgetKeyForm(from, id); | |
| 96 | if (done === "unknown") { | |
| 97 | if (forget === "") return notFoundPage(ctx); | |
| 98 | const gone = page({ ctx, title: "No such link", body: html`${pageHead("No such link")}<p>This link is not here any more.</p>${raw(forget)}` }, 404); | |
| 99 | gone.headers.set("cache-control", "no-store"); | |
| 100 | return gone; | |
| 101 | } | |
| 102 | if (done === "wrong") return refusal(ctx, 403, "That key does not match this link, so it is still shared. Nothing changed.", "Not stopped"); | |
| 103 | const res = page({ ctx, title: "Sharing stopped", body: html`${pageHead(html`Sharing stopped`)}<p>The link is gone: it now opens nothing.</p>${raw(forget)}<p><a href="/tab">Back to the tab forge</a></p>` }); | |
| 104 | res.headers.set("cache-control", "no-store"); | |
| 105 | return res; | |
| 106 | } | |
| 107 | ||
| 75 | 108 | export function tabLinkOpen(ctx: Ctx): Response { |
| 76 | 109 | const id = ctx.params.id ?? ""; |
| 77 | 110 | const app = isShareId(id) ? sharedApp(store(ctx), id) : null; |
new above
offline
The new
revokedoor has no test. Add one that makes 11 revoke posts from one address and sees a 429, while a make from the same address still answers.