Public: anyone can read this; the crew can change it.
A forge asleep for a client shows a plain 'Waking up' page with a retry that needs no script #14094
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14084-a-forge-asleep-for-a-client-shows-a-plai → main 8 commits fork 3 threads · 3 unresolved
11 files
changed +126
−58
src/kernel/destroy_reach.ts −1
| @@ -93,7 +93,6 @@ export const ALLOWED_REMOVALS: readonly { unit: string; why: string }[] = [ | ||
| 93 | 93 | { unit: "src/actions/spawn.ts:unmake", why: "removes the directory and ledger of a child whose first attempt failed before it was ever finished, and only that call's own (never a finished or resumed one): nothing of anyone's work is in it (#13135)" }, |
| 94 | 94 | { unit: "src/spawn/own_code.ts:checkout", why: "removes a half-made export of the forge's own code, keyed by commit" }, |
| 95 | 95 | { unit: "src/spawn/own_code.ts:recordGood", why: "removes exports of the forge's own code for other commits than the good one" }, |
| 96 | { unit: "src/web/asset.ts:prune", why: "removes cached page scripts older than their keep time" }, | |
| 97 | 96 | ]; |
| 98 | 97 | |
| 99 | 98 | const REMOVERS = ["rmSync", "rmdirSync", "unlinkSync", "rm", "rmdir", "unlink"]; |
src/spawn/host.ts +9 −9
| @@ -620,10 +620,10 @@ export async function wakeGate(parent: App, request: Request): Promise<Response | ||
| 620 | 620 | if (ledger === undefined || !ledger.done) return undefined; |
| 621 | 621 | // Being moved into its own cell: closed here and not yet proven there. It answers again in a |
| 622 | 622 | // moment, and the page asks by itself. |
| 623 | if (ledger.moving) return wakingResponse(parent, request, name); | |
| 623 | if (ledger.moving) return wakingResponse(request, name); | |
| 624 | 624 | // Placed in this process on a host that opens none there: it waits for its move, and takes no |
| 625 | 625 | // place among the forges waking. |
| 626 | if (ledger.placement !== "cell" && isSealed(parent)) return wakingResponse(parent, request, name, waitsToMove(name)); | |
| 626 | if (ledger.placement !== "cell" && isSealed(parent)) return wakingResponse(request, name, waitsToMove(name)); | |
| 627 | 627 | keepSweeping(parent); |
| 628 | 628 | keepWatchingFloor(parent); |
| 629 | 629 | // Below the disk floor an awake child is put to sleep now, not at the next look, |
| @@ -664,7 +664,7 @@ export async function wakeGate(parent: App, request: Request): Promise<Response | ||
| 664 | 664 | if (!reserved) waking.set(parent, (reserved = new Map())); |
| 665 | 665 | if (reservedCount(parent) > 0 && reserved.has(ledger.bodyId)) return undefined; |
| 666 | 666 | const verdict = takeDoor(parent, "api", request); |
| 667 | if (!verdict.allowed) return wakingResponse(parent, request, name, "too many requests to sleeping forges from your address; try again in a minute"); | |
| 667 | if (!verdict.allowed) return wakingResponse(request, name, "too many requests to sleeping forges from your address; try again in a minute"); | |
| 668 | 668 | let rates = wakeRates.get(parent); |
| 669 | 669 | if (!rates) wakeRates.set(parent, (rates = new WakeRate())); |
| 670 | 670 | const at = gateClock.now(); |
| @@ -675,11 +675,11 @@ export async function wakeGate(parent: App, request: Request): Promise<Response | ||
| 675 | 675 | const own = isParentsOwn(ledger, request); |
| 676 | 676 | const wait = own ? 0 : people.waitS(budget.key, max, at); |
| 677 | 677 | if (wait > 0) |
| 678 | return wakingResponse(parent, request, name, budgetRefusal({ name, budget, max, waitS: wait, limitsUrl: `${parentOrigin(parent.config)}/admin/limits` }), wait); | |
| 678 | return wakingResponse(request, name, budgetRefusal({ name, budget, max, waitS: wait, limitsUrl: `${parentOrigin(parent.config)}/admin/limits` }), wait); | |
| 679 | 679 | const why = (await roomFor(parent)) ?? (known ? undefined : rates.refusal(ledger.bodyId, at)); |
| 680 | 680 | if (why !== undefined) { |
| 681 | 681 | const stop = lastStop(parent, ledger.bodyId); |
| 682 | return wakingResponse(parent, request, name, stop === undefined ? why : stopSentence(stop)); | |
| 682 | return wakingResponse(request, name, stop === undefined ? why : stopSentence(stop)); | |
| 683 | 683 | } |
| 684 | 684 | if (!known) rates.note(ledger.bodyId, at); |
| 685 | 685 | if (!own) people.note(budget.key, at); |
| @@ -1093,8 +1093,8 @@ export const hostedChildApps = childAppsSummary; | ||
| 1093 | 1093 | export async function answerFromCell(parent: App, request: Request, named?: string): Promise<Response> { |
| 1094 | 1094 | const name = named ?? parseHostedChildName(request.headers.get("host") ?? "", childHost(parent)); |
| 1095 | 1095 | const ledger = name === undefined ? undefined : readLedgerSync(parent, name); |
| 1096 | if (ledger !== undefined && ledger.moving) return wakingResponse(parent, request, ledger.name); | |
| 1097 | if (ledger !== undefined && ledger.placement !== "cell" && isSealed(parent)) return wakingResponse(parent, request, ledger.name, waitsToMove(ledger.name)); | |
| 1096 | if (ledger !== undefined && ledger.moving) return wakingResponse(request, ledger.name); | |
| 1097 | if (ledger !== undefined && ledger.placement !== "cell" && isSealed(parent)) return wakingResponse(request, ledger.name, waitsToMove(ledger.name)); | |
| 1098 | 1098 | if (ledger === undefined || ledger.placement !== "cell") return new Response("not found", { status: 404 }); |
| 1099 | 1099 | const cells = cellChildren(parent); |
| 1100 | 1100 | const child = cells.get(ledger.bodyId); |
| @@ -1113,7 +1113,7 @@ export async function answerFromCell(parent: App, request: Request, named?: stri | ||
| 1113 | 1113 | // Only so many wait on one cell: the rest are told it is waking at once, so a crowd cannot pin |
| 1114 | 1114 | // connections and bodies. |
| 1115 | 1115 | const waiting = waiters.get(ledger.bodyId) ?? 0; |
| 1116 | if (waiting >= wakeLimits.waiters) return wakingResponse(parent, request, ledger.name, undefined, 5, ledger.wakeMs); | |
| 1116 | if (waiting >= wakeLimits.waiters) return wakingResponse(request, ledger.name, undefined, 5, ledger.wakeMs); | |
| 1117 | 1117 | waiters.set(ledger.bodyId, waiting + 1); |
| 1118 | 1118 | let woke: CellChild | undefined; |
| 1119 | 1119 | try { |
| @@ -1134,7 +1134,7 @@ export async function answerFromCell(parent: App, request: Request, named?: stri | ||
| 1134 | 1134 | // A cell that did not start says so, with when the host tries again: never "waking up" without |
| 1135 | 1135 | // end. |
| 1136 | 1136 | const stop = cells.failure(ledger.bodyId) === undefined ? undefined : lastStop(parent, ledger.bodyId); |
| 1137 | return wakingResponse(parent, request, ledger.name, stop === undefined ? undefined : stopSentence(stop), 5, ledger.wakeMs); | |
| 1137 | return wakingResponse(request, ledger.name, stop === undefined ? undefined : stopSentence(stop), 5, ledger.wakeMs); | |
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | 1140 | /** |
src/web/pages/waking.ts +46 −31
| @@ -1,44 +1,59 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * What a visitor sees at a sleeping forge's address: it is waking, or the host |
| 3 | * will not wake it right now. Drawn with the page shell and its components, so | |
| 4 | * it follows the theme; a browser asks again by itself (`refresh`), a git | |
| 5 | * client or an API call gets a sentence (`spawn/sleep.ts` `wakingText`). | |
| 3 | * will not wake it right now. A client must never see a raw error, so the page | |
| 4 | * is one sentence in a document of its own: no script, one hashed style, no shell (the | |
| 5 | * shell's palette lists the parent's apps), and no name, host or id. The | |
| 6 | * browser asks again by itself (`<meta http-equiv="refresh">`) and a link | |
| 7 | * retries by hand; a git client | |
| 8 | * or an API call gets a sentence (`spawn/sleep.ts` `wakingText`). | |
| 6 | 9 | */ |
| 7 | 10 | |
| 8 | import type { App } from "../../app.ts"; | |
| 9 | import type { Ctx } from "../../http/context.ts"; | |
| 11 | import { createHash } from "node:crypto"; | |
| 12 | import { THEMES } from "../../design/themes.ts"; | |
| 13 | import { securityFloor } from "../../http/respond.ts"; | |
| 10 | 14 | import { wakingText } from "../../spawn/sleep.ts"; |
| 11 | import { btn, empty } from "../ui.ts"; | |
| 12 | import { html } from "../html.ts"; | |
| 13 | import { page } from "../layout.ts"; | |
| 14 | import { wakeSeconds, wakingSentence } from "../retry_words.ts"; | |
| 15 | import { escapeHtml } from "../html.ts"; | |
| 16 | import { triesAgain, wakeSeconds } from "../retry_words.ts"; | |
| 17 | ||
| 18 | const light = THEMES.light.tokens; | |
| 19 | const dark = THEMES.dark.tokens; | |
| 20 | /** | |
| 21 | * The forge's tokens inlined (the page cannot load the stylesheet it stands in for): a narrow | |
| 22 | * measure, generous rhythm. | |
| 23 | */ | |
| 24 | const STYLE = | |
| 25 | `:root{color-scheme:light dark;--bg:${light.bg};--fg:${light.fg};--accent:${light.accent}}` + | |
| 26 | `@media(prefers-color-scheme:dark){:root{--bg:${dark.bg};--fg:${dark.fg};--accent:${dark.accent}}}` + | |
| 27 | `body{margin:0;background:var(--bg);color:var(--fg);font:14px/1.5 system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif}` + | |
| 28 | `main{max-width:36rem;margin:0 auto;padding:4rem 16px}` + | |
outdated
Principles 3, 4, 5: no style, so no --bg/--fg tokens, no margins or measure, and no way to reach a retry on a phone. Add tokenised styling and a plain <a href> retry link; the 429 page especially has no way forward as it is. |
||
| 29 | `h1{font-size:20px;font-weight:620;letter-spacing:-.02em;line-height:1.25;margin:0 0 .75rem}` + | |
| 30 | `p{margin:0 0 1.5rem}a{color:var(--accent)}`; | |
| 31 | /** Nothing loads, nothing runs: the one stylesheet is admitted by hash. */ | |
| 32 | const POLICY = `default-src 'none'; style-src 'sha256-${createHash("sha256").update(STYLE).digest("base64")}'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'`; | |
| 15 | 33 | |
| 16 | 34 | /** Waking (`why` undefined, 503) or refused (`why` a sentence, 429), as a page when the visitor asks for HTML. */ |
| 17 | export function wakingResponse(app: App, request: Request, name: string, why?: string, retryS = 5, wakeMs?: number): Response { | |
| 35 | export function wakingResponse(request: Request, name: string, why?: string, retryS = 5, wakeMs?: number): Response { | |
| 18 | 36 | // One number answers "when": the words, Refresh and Retry-After. A refusal keeps the caller's |
| 19 | 37 | // own. |
| 20 | 38 | const aboutS = why === undefined ? wakeSeconds(wakeMs) : retryS; |
| 21 | 39 | if (!(request.headers.get("accept") ?? "").includes("text/html")) return wakingText(name, why, aboutS); |
| 22 | const url = new URL(request.url); | |
| 23 | const ctx: Ctx = { app, request, url, params: {}, auth: { user: undefined, scope: undefined, via: "none" }, theme: undefined }; | |
| 24 | const response = page( | |
| 25 | { | |
| 26 | ctx, | |
| 27 | bare: true, | |
| 28 | title: why === undefined ? "Waking up" : "Not now", | |
| 29 | body: html`<div class="narrow-wide"> | |
| 30 | ${empty({ | |
| 31 | icon: "history", | |
| 32 | title: why === undefined ? "Waking up" : "Not now", | |
| 33 | note: why ?? wakingSentence(name, wakeMs), | |
| 34 | action: btn("Try again", { href: url.pathname, variant: "primary" }), | |
| 35 | })} | |
| 36 | </div>`, | |
| 40 | const waking = why === undefined; | |
| 41 | const title = waking ? "Waking up" : "Not now"; | |
| 42 | const sentence = why ?? `This forge was asleep and is waking up. ${triesAgain(aboutS)}`; | |
| 43 | // A link navigates where a refresh may be blocked; the path is the request's own, escaped. | |
| 44 | const here = escapeHtml(new URL(request.url).pathname); | |
| 45 | const body = `<!doctype html><html lang="en"><head><meta charset="utf-8">${ | |
| 46 | waking ? `<meta http-equiv="refresh" content="${aboutS}">` : "" | |
| 47 | }<meta name="viewport" content="width=device-width, initial-scale=1"><title>${title}</title><style>${STYLE}</style></head><body><main><h1>${title}</h1><p>${escapeHtml(sentence)}</p><p><a href="${here}">Try again</a></p></main></body></html>`; | |
| 48 | const response = new Response(body, { | |
| 49 | status: waking ? 503 : 429, | |
| 50 | headers: { | |
| 51 | "content-type": "text/html; charset=utf-8", | |
| 52 | "content-security-policy": POLICY, | |
| 53 | "retry-after": String(aboutS), | |
| 54 | "cache-control": "no-store", | |
| 55 | ...(waking ? { refresh: String(aboutS) } : {}), | |
| 37 | 56 | }, |
| 38 | why === undefined ? 503 : 429, | |
| 39 | ); | |
| 40 | response.headers.set("retry-after", String(aboutS)); | |
| 41 | response.headers.set("cache-control", "no-store"); | |
| 42 | if (why === undefined) response.headers.set("refresh", String(aboutS)); | |
| 43 | return response; | |
| 57 | }); | |
| 58 | return securityFloor(response); | |
| 44 | 59 | } |
src/web/retry_words.ts −8
| @@ -16,11 +16,3 @@ export function wakeSeconds(ms: unknown): number { | ||
| 16 | 16 | export function triesAgain(seconds: number): string { |
| 17 | 17 | return `This page tries again in about ${seconds} second${seconds === 1 ? "" : "s"}.`; |
| 18 | 18 | } |
| 19 | ||
| 20 | /** | |
| 21 | * `homie was asleep and is starting. This page tries again in about 8 seconds.` (`ms`: the last | |
| 22 | * measured start). | |
| 23 | */ | |
| 24 | export function wakingSentence(name: string, ms?: number): string { | |
| 25 | return `${name} was asleep and is starting. ${triesAgain(wakeSeconds(ms))}`; | |
| 26 | } |
test/first-ten-minutes.test.ts +1 −1
| @@ -202,7 +202,7 @@ describe("a request while a cell wakes", () => { | ||
| 202 | 202 | const res = await answerFromCell(parent, post()); |
| 203 | 203 | expect(woken).toBe(false); // answered while the wake is still under way |
| 204 | 204 | expect(res.status).toBe(503); |
| 205 | expect(await res.text()).toContain("was asleep and is starting"); | |
| 205 | expect(await res.text()).toContain("is waking up"); | |
| 206 | 206 | } finally { |
| 207 | 207 | wake.open(undefined); |
| 208 | 208 | wakeLimits.waitMs = was; |
test/forge-sleep.test.ts +2 −2
| @@ -163,7 +163,7 @@ describe("a hosted forge scales to zero", () => { | ||
| 163 | 163 | rates.note("b", 2000); |
| 164 | 164 | expect(rates.refusal("b", 3000, env)).toContain("woken 2 times"); |
| 165 | 165 | expect(rates.refusal("b", 3000 + 3_600_000, env)).toBeUndefined(); |
| 166 | const refused = wakingResponse(parent, new Request("https://x"), "homie", "too many"); | |
| 166 | const refused = wakingResponse(new Request("https://x"), "homie", "too many"); | |
| 167 | 167 | expect(refused.status).toBe(429); |
| 168 | 168 | expect(await refused.text()).toBe("too many"); |
| 169 | 169 | }); |
| @@ -182,7 +182,7 @@ describe("a hosted forge scales to zero", () => { | ||
| 182 | 182 | }); |
| 183 | 183 | |
| 184 | 184 | test("a waking page is plain for a browser, and the gate lets an awake forge through", async () => { |
| 185 | const page = wakingResponse(parent, new Request("https://forge.test/", { headers: { accept: "text/html" } }), "homie"); | |
| 185 | const page = wakingResponse(new Request("https://forge.test/", { headers: { accept: "text/html" } }), "homie"); | |
| 186 | 186 | expect(page.status).toBe(503); |
| 187 | 187 | expect(page.headers.get("refresh")).toBe("5"); |
| 188 | 188 | const text = await page.text(); |
test/loading-chrome.looks.test.ts +1 −1
| @@ -49,7 +49,7 @@ describe.skipIf(chromium === undefined)("loading, watched in Chromium", () => { | ||
| 49 | 49 | port: 0, |
| 50 | 50 | fetch: async (request) => { |
| 51 | 51 | const url = new URL(request.url); |
| 52 | if (url.pathname === "/__waking") return wakingResponse(app, request, "demo"); | |
| 52 | if (url.pathname === "/__waking") return wakingResponse(request, "demo"); | |
| 53 | 53 | const headers = new Headers(request.headers); |
| 54 | 54 | headers.delete("host"); |
| 55 | 55 | headers.set("accept-encoding", "identity"); |
test/no-polling.test.ts +1
| @@ -101,6 +101,7 @@ async function render(base: string, path: string, cookie: string): Promise<{ sta | ||
| 101 | 101 | const ALLOWED: Record<string, { allow: string[]; why: string }> = { |
| 102 | 102 | "src/web/sw.ts": { allow: ['http-equiv="refresh"'], why: "the restart page: the forge is down, so there is no /events to hear" }, |
| 103 | 103 | "src/web/pages/offline.ts": { allow: ['http-equiv="refresh"'], why: "the offline page: the forge is unreachable, so there is no /events to hear" }, |
| 104 | "src/web/pages/waking.ts": { allow: ['http-equiv="refresh"'], why: "the waking page: the forge is asleep, so there is no /events to hear" }, | |
| 104 | 105 | "src/web/pages/talk.ts": { allow: ["setInterval"], why: "server side: the stream of one turn watches the run's row, which has no event to hear" }, |
| 105 | 106 | "src/web/client.ts": { allow: ["setInterval"], why: "clocks that only redraw text" }, |
| 106 | 107 | "src/web/space_client.ts": { allow: ["setInterval"], why: "the map clock label only redraws text; it fetches and reloads nothing" }, |
test/retry-words.test.ts +3 −3
| @@ -5,7 +5,7 @@ import { tmpdir } from "node:os"; | ||
| 5 | 5 | import { join } from "node:path"; |
| 6 | 6 | import { offlineHtml } from "../src/web/pages/offline.ts"; |
| 7 | 7 | import { wakingResponse } from "../src/web/pages/waking.ts"; |
| 8 | import { triesAgain, wakeSeconds, wakingSentence } from "../src/web/retry_words.ts"; | |
| 8 | import { triesAgain, wakeSeconds } from "../src/web/retry_words.ts"; | |
| 9 | 9 | |
| 10 | 10 | describe("when the forge will answer", () => { |
| 11 | 11 | test("a measured start becomes whole seconds, clamped; none measured is the default", () => { |
| @@ -19,11 +19,11 @@ describe("when the forge will answer", () => { | ||
| 19 | 19 | test("the waking page says about how long, and refreshes once after that long", async () => { |
| 20 | 20 | const app = createApp({ dataDir: mkdtempSync(join(tmpdir(), "forge-wake-")), port: 0 }); |
| 21 | 21 | try { |
| 22 | const res = wakingResponse(app, new Request("https://x/", { headers: { accept: "text/html" } }), "homie", undefined, 5, 7400); | |
| 22 | const res = wakingResponse(new Request("https://x/", { headers: { accept: "text/html" } }), "homie", undefined, 5, 7400); | |
| 23 | 23 | expect(res.headers.get("refresh")).toBe("8"); |
| 24 | 24 | expect(res.headers.get("retry-after")).toBe("8"); |
| 25 | 25 | const text = await res.text(); |
| 26 | expect(text).toContain(wakingSentence("homie", 7400)); | |
| 26 | expect(text).toContain("This page tries again in about 8 seconds."); | |
| 27 | 27 | expect(text).not.toContain("Starting, about"); |
| 28 | 28 | expect(text.match(/tries again/g)?.length).toBe(1); |
| 29 | 29 | } finally { |
test/spawn-cell-stays.test.ts +1 −2
| @@ -16,7 +16,6 @@ import { cellChildren, type CellChild } from "../src/spawn/cell.ts"; | ||
| 16 | 16 | import { answerFromCell, bootHostedChild, closeHostedChildren, NOT_STARTED, provideCellsForTest, ranOwnCode, resolveHostedChild, wakeLimits } from "../src/spawn/host.ts"; |
| 17 | 17 | import { readOwnCode, switchOwnCode } from "../src/spawn/own_code.ts"; |
| 18 | 18 | import { cancelRestarts, lastStop, stopSentence } from "../src/spawn/stopped.ts"; |
| 19 | import { wakingSentence } from "../src/web/retry_words.ts"; | |
| 20 | 19 | import { quietLogs } from "./helpers/globals.ts"; |
| 21 | 20 | |
| 22 | 21 | quietLogs(); |
| @@ -167,7 +166,7 @@ describe("how long a start took", () => { | ||
| 167 | 166 | expect(waking.status).toBe(503); |
| 168 | 167 | expect(waking.headers.get("refresh")).toBe("8"); |
| 169 | 168 | expect(waking.headers.get("retry-after")).toBe("8"); |
| 170 | expect(await waking.text()).toContain(wakingSentence("alpha", 7500)); | |
| 169 | expect(await waking.text()).toContain("This page tries again in about 8 seconds."); | |
| 171 | 170 | } finally { |
| 172 | 171 | Date.now = realNow; |
| 173 | 172 | wakeLimits.waitMs = waitMs; |
test/waking-plain.test.ts added +62
| @@ -0,0 +1,62 @@ | ||
| 1 | import { describe, expect, test } from "bun:test"; | |
| 2 | import { wakingResponse } from "../src/web/pages/waking.ts"; | |
| 3 | ||
| 4 | const ask = () => | |
| 5 | wakingResponse(new Request("https://homie--forge.internal.test/x", { headers: { accept: "text/html" } }), "homie-secret-name"); | |
| 6 | ||
| 7 | describe("the waking page is plain", () => { | |
| 8 | test("one sentence and a meta refresh, no script needed to retry", async () => { | |
| 9 | const res = ask(); | |
| 10 | expect(res.status).toBe(503); | |
| 11 | const text = await res.text(); | |
| 12 | expect(text).toContain('http-equiv="refresh" content="5"'); | |
| 13 | expect(text.match(/<p>/g)?.length).toBe(2); // the sentence and the link | |
| 14 | expect(text).toContain('<a href="/x">Try again</a>'); | |
| 15 | expect(text).toContain("is waking up"); | |
| 16 | expect(text).not.toContain("<script"); | |
| 17 | }); | |
| 18 | ||
| 19 | test("it shows no stack, host or internal id", async () => { | |
| 20 | const text = await ask().text(); | |
| 21 | for (const leak of ["homie-secret-name", "homie--forge", "internal.test", "at Object", ".ts:", "Error:", "stack"]) | |
| 22 | expect(text).not.toContain(leak); | |
| 23 | }); | |
| 24 | ||
| 25 | test("the security headers are kept", async () => { | |
| 26 | const res = ask(); | |
| 27 | expect(res.headers.get("content-security-policy")).toBeTruthy(); | |
| 28 | expect(res.headers.get("x-content-type-options")).toBe("nosniff"); | |
| 29 | expect(res.headers.get("referrer-policy")).toBeTruthy(); | |
| 30 | expect(res.headers.get("cache-control")).toBe("no-store"); | |
| 31 | }); | |
| 32 | ||
| 33 | test("a refusal is 429, escaped, names no forge, has no refresh and a link to tap", async () => { | |
outdated
Add a test for the 429 path with a hostile |
||
| 34 | const hostile = "<script>alert(1)</script> & \"quoted\""; | |
| 35 | const res = wakingResponse( | |
| 36 | new Request("https://homie--forge.internal.test/x?a=1", { headers: { accept: "text/html" } }), | |
| 37 | "homie-secret-name", | |
| 38 | hostile, | |
| 39 | 30, | |
| 40 | ); | |
| 41 | expect(res.status).toBe(429); | |
| 42 | expect(res.headers.get("refresh")).toBeNull(); | |
| 43 | expect(res.headers.get("retry-after")).toBe("30"); | |
| 44 | const text = await res.text(); | |
| 45 | expect(text).not.toContain("<script"); | |
| 46 | expect(text).toContain("<script>alert(1)</script>"); | |
| 47 | expect(text).not.toContain("http-equiv"); | |
| 48 | expect(text).toContain('<a href="/x">Try again</a>'); | |
| 49 | for (const leak of ["homie-secret-name", "homie--forge", "internal.test"]) expect(text).not.toContain(leak); | |
| 50 | }); | |
| 51 | ||
| 52 | test("the page uses the forge's tokens in one hashed style, and no script is allowed", async () => { | |
| 53 | const res = ask(); | |
| 54 | const csp = res.headers.get("content-security-policy") ?? ""; | |
| 55 | expect(csp).toMatch(/style-src 'sha256-[A-Za-z0-9+/=]+'/); | |
| 56 | expect(csp).not.toContain("script-src"); | |
| 57 | expect(csp).toContain("default-src 'none'"); | |
| 58 | const text = await res.text(); | |
| 59 | expect(text).toContain("var(--bg)"); | |
| 60 | expect(text).toContain("max-width:36rem"); | |
| 61 | }); | |
| 62 | }); |
new above
offline
Unused
_appparameter: remove it and the callers' argument.