Public: anyone can read this; the crew can change it.
/security tells a visitor in plain words how the forge keeps them safe and how to report a problem #13216
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13208-security-tells-a-visitor-in-plain-words → main 8 commits fork 4 threads · 4 unresolved
18 files
changed +385
−14
docs/design/audit.md +1
| @@ -79,6 +79,7 @@ Machine routes are not pages and have no entry: `/audit.csv`, | ||
| 79 | 79 | - `/displays` — `pages/displays.ts` · every display the viewer may read, each with its layout, repository and showcased demos; a stranger signs in first · none yet (read only; a repository's display is its own page) · none seen. |
| 80 | 80 | - `/api` — `pages/api.ts` · the forge's OpenAPI operations by area, with search and Try it, public · the footer, the OpenAPI document, the terminal's API screen · none seen. An app's own spec is its `/:owner/:name/api` tab. |
| 81 | 81 | - `/contribute` — `pages/contribute.ts` · what this forge is and where outside work is welcome, open to anyone · `/llms.txt`, MCP `contribute` tool · none seen. |
| 82 | - `/security` — `pages/security_public.ts` · how the forge keeps a visitor safe and how to report a problem, each claim with its code and test, public · the footer, `/.well-known/security.txt`, `/settings/security` (the admin's side) · none seen. | |
| 82 | 83 | - `/agents`: `pages/agents.ts` · `/llms.txt` drawn as a page for an assistant whose reader takes only HTML, and for the person beside it, public · the home page's prompt and its Open in ChatGPT, Claude and Grok links · none seen. |
| 83 | 84 | - `/search` — `pages/search.ts` · find across what I can read · the palette (`palette.ts`) · none seen. |
| 84 | 85 | - `/-/confirm` — `pages/search.ts` (`confirmPage`) · the "are you sure" step for a destructive action · none · none seen. |
docs/features/README.md +1
| @@ -403,6 +403,7 @@ Read with the guide page [Backups and moving](../guide-backups-moving.md). | ||
| 403 | 403 | Read with the guide page [](../guide-settings.md). |
| 404 | 404 | |
| 405 | 405 | - [](account-help.md) |
| 406 | - [](security.md) | |
| 406 | 407 | - [](devices.md) |
| 407 | 408 | - [](edge-only-accounts.md) |
| 408 | 409 | - [](knobs.md) |
docs/features/security.md added +16
| @@ -0,0 +1,16 @@ | ||
| 1 | # Security, for a visitor | |
| 2 | ||
| 3 | `/security` says in plain words what this forge enforces for every app and every visitor with no | |
| 4 | setting (egress refused by name, code in a cell, sandboxed agents, the sign-in cookie, the | |
| 5 | cross-site refusal, the response headers) and how to report a problem with no account: the | |
| 6 | security contact, a sealed security issue, `/<owner>/<name>/report` and an app's own | |
| 7 | `/__forge/report`. Each row names the file that enforces it. | |
| 8 | ||
| 9 | Try it: signed out, follow **Security** in the foot of any page, or open `/security`. | |
| 10 | ||
| 11 | The terminal: open the palette and choose **Security**; the same rows scroll with `j`/`k`, `q` | |
| 12 | closes. Both read `src/view/security.ts`. | |
| 13 | ||
| 14 | Every claim names its source and its proof, and `test/security-page.test.ts` fails when a source | |
| 15 | no longer says what the claim leans on or the proof is gone. Machines read | |
| 16 | `/.well-known/security.txt`; the admin's side is `/settings/security`. |
forge.json +1 −1
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | "api.github.com" |
| 5 | 5 | ], |
| 6 | 6 | "app": { |
| 7 | "looks": ["/", "/docs", "/explore", "/board", "/notes", "/review", "/releases", "/apps", "/map", "/system", "/maintenance", "/talk", "/flow", "/resilience", "/boards?help", "/settings/crew", "/settings/crew?help", "/settings/security/controls", "/preview-admin/sample", "/preview-admin/sample/pulls/3", "/preview-admin/sample/next?pick", "/preview-admin/sample/bets", "/preview-admin/sample/waves", "/preview-admin/sample/space"], | |
| 7 | "looks": ["/", "/docs", "/explore", "/board", "/notes", "/review", "/releases", "/apps", "/security", "/system", "/maintenance", "/talk", "/flow", "/resilience", "/boards?help", "/settings/crew", "/settings/crew?help", "/settings/security/controls", "/preview-admin/sample", "/preview-admin/sample/pulls/3", "/preview-admin/sample/next?pick", "/preview-admin/sample/bets", "/preview-admin/sample/waves", "/preview-admin/sample/space"], | |
| 8 | 8 | "looksAsOwner": ["/", "/board", "/flow", "/boards?help", "/settings/crew", "/settings/crew?help", "/settings/security/controls", "/talk", "/system", "/maintenance", "/resilience", "/preview-admin/sample", "/preview-admin/sample/pulls/3", "/preview-admin/sample/next?pick", "/preview-admin/sample/bets", "/preview-admin/sample/waves", "/preview-admin/sample/space"], |
| 9 | 9 | "run": "bun run src/main.ts", |
| 10 | 10 | "install": "", |
src/core/reserved.ts +1
| @@ -36,6 +36,7 @@ export const SYSTEM_NAMES: readonly string[] = [ | ||
| 36 | 36 | "agent", |
| 37 | 37 | "agents", |
| 38 | 38 | "privacy", |
| 39 | "security", | |
| 39 | 40 | "pricing", |
| 40 | 41 | "bot", |
| 41 | 42 | "steward", |
src/crew/runner.ts +11 −4
| @@ -645,7 +645,10 @@ async function forkTipOf(app: App, pull: Pull): Promise<string | undefined> { | ||
| 645 | 645 | ); |
| 646 | 646 | } |
| 647 | 647 | |
| 648 | /** What a retried follow-up is told: the latest verdict asking for changes, and the last builder run's final answer. */ | |
| 648 | /** | |
| 649 | * What a retried follow-up is told: the latest verdict asking for changes, and the last builder | |
| 650 | * run's final answer. | |
| 651 | */ | |
| 649 | 652 | function lastTryOf( |
| 650 | 653 | app: App, |
| 651 | 654 | pullId: string, |
| @@ -934,7 +937,10 @@ export interface Pause { | ||
| 934 | 937 | readonly summary?: string | undefined; |
| 935 | 938 | } |
| 936 | 939 | |
| 937 | /** The file names a conflict or converge run's summary carries, after "main|parent|upstream moved: ". */ | |
| 940 | /** | |
| 941 | * The file names a conflict or converge run's summary carries, after "main|parent|upstream moved: | |
| 942 | * ". | |
| 943 | */ | |
| 938 | 944 | export function conflictFilesOf(summary: string): string[] { |
| 939 | 945 | return summary |
| 940 | 946 | .replace(/^(main|parent|upstream) moved: /, "") |
| @@ -2438,8 +2444,9 @@ export function holdModelCredential(key: string, env: Record<string, string>): s | ||
| 2438 | 2444 | */ |
| 2439 | 2445 | export function credentialEnv(picked: Pick, dataDir?: string): Record<string, string> { |
| 2440 | 2446 | if (picked.kind === "ready") return credentialEnvOf(picked); |
| 2441 | // A forge its parent funds (#10484): with no account of its own, the crew calls the model through the parent. | |
| 2442 | // "none" reaches here only under an owner's grant (an org's, #10991), which is the forge's account too. | |
| 2447 | // A forge its parent funds (#10484): with no account of its own, the crew calls the model through | |
| 2448 | // the parent. "none" reaches here only under an owner's grant (an org's, #10991), which is the | |
| 2449 | // forge's account too. | |
| 2443 | 2450 | const lent = (picked.kind === "env" || picked.kind === "none") && dataDir !== undefined ? fundedEnv(dataDir) : undefined; |
| 2444 | 2451 | if (lent !== undefined) return lent; |
| 2445 | 2452 | return ownEnv(); |
src/http/route_marks.ts +1
| @@ -162,6 +162,7 @@ export const HEADS: Readonly<Record<string, Mark | "mixed">> = { | ||
| 162 | 162 | "/plugins": "open", |
| 163 | 163 | "/pricing": "open", |
| 164 | 164 | "/privacy": "open", |
| 165 | "/security": "open", | |
| 165 | 166 | "/recover": "open", |
| 166 | 167 | "/releases": "admin", |
| 167 | 168 | "/releases.json": "open", |
src/http/server.ts +2
| @@ -24,6 +24,7 @@ import { secureFor } from "./cookie_secure.ts"; | ||
| 24 | 24 | import { refusedByDatabase, shownRefusal } from "./refusal.ts"; |
| 25 | 25 | import { NOT_A_MEMBER } from "../core/roles.ts"; |
| 26 | 26 | import { privacyPage } from "../web/pages/privacy.ts"; |
| 27 | import { publicSecurityPage } from "../web/pages/security_public.ts"; | |
| 27 | 28 | import { startClaimAccountSubmit, startClaimPage, startClaimSubmit } from "../web/pages/start_claim.ts"; |
| 28 | 29 | import { signupOptions, signupPasskey } from "../web/pages/signup-passkey.ts"; |
| 29 | 30 | import { toolbarComment, toolbarPage } from "../web/studio/toolbar.ts"; |
| @@ -1056,6 +1057,7 @@ export function buildRouter(): Router<Handler> { | ||
| 1056 | 1057 | router.add("GET", "/releases", releasesPage); |
| 1057 | 1058 | // The forge's own documentation: a redirect built from configuration only. |
| 1058 | 1059 | router.add("GET", "/privacy", privacyPage); |
| 1060 | router.add("GET", "/security", publicSecurityPage); | |
| 1059 | 1061 | router.add("GET", "/docs", docsFolder); |
| 1060 | 1062 | router.add("GET", "/docs/:file", docsFile); |
| 1061 | 1063 | router.add("GET", "/docs/features/:file", docsFeature); |
src/tui/forge.ts +18 −5
| @@ -54,6 +54,7 @@ import { askedScreen } from "./screens/asked.ts"; | ||
| 54 | 54 | import { notesScreen } from "./screens/thoughtnotes.ts"; |
| 55 | 55 | import { deciderScreen } from "./screens/decider.ts"; |
| 56 | 56 | import { familyScreen } from "./screens/family.ts"; |
| 57 | import { securityScreen } from "./screens/security_public.ts"; | |
| 57 | 58 | import { familyLines, familyView } from "../spawn/family.ts"; |
| 58 | 59 | import { issueScreen } from "./screens/issue.ts"; |
| 59 | 60 | import { pullScreen } from "./screens/pull.ts"; |
| @@ -359,7 +360,8 @@ export function forgeCommands(session: Session): (ctx: Ctx) => Command[] { | ||
| 359 | 360 | hint: "paste a link from another forge; it runs here", |
| 360 | 361 | run: () => ctx.push(bringScreen(session, ctx, blank("Bring an app"))), |
| 361 | 362 | }); |
| 362 | // An organization you own, as /organizations/new and MCP `org_create` make it: a person's, never an agent's (#7260). | |
| 363 | // An organization you own, as /organizations/new and MCP `org_create` make it: a person's, | |
| 364 | // never an agent's (#7260). | |
| 363 | 365 | if (session.user !== undefined && session.user.kind !== "agent") |
| 364 | 366 | commands.push({ |
| 365 | 367 | id: "new-org", |
| @@ -543,7 +545,8 @@ export function forgeCommands(session: Session): (ctx: Ctx) => Command[] { | ||
| 543 | 545 | hint: "concurrency and guards, live; e changes a settable one", |
| 544 | 546 | run: () => ctx.push(capacityScreen(session, ctx)), |
| 545 | 547 | }); |
| 546 | // What crawlers cost and who was refused, as GET /api/v1/admin/crawlers: the capacity screen's readers. | |
| 548 | // What crawlers cost and who was refused, as GET /api/v1/admin/crawlers: the capacity screen's | |
| 549 | // readers. | |
| 547 | 550 | if (mayCapacity(session)) |
| 548 | 551 | commands.push({ |
| 549 | 552 | id: "crawlers", |
| @@ -572,7 +575,8 @@ export function forgeCommands(session: Session): (ctx: Ctx) => Command[] { | ||
| 572 | 575 | hint: "the last 30 releases and their pulls", |
| 573 | 576 | run: () => ctx.push(changelogScreen(session, ctx)), |
| 574 | 577 | }); |
| 575 | // The live release and the kept ones, as /releases gates them: a site admin or a reader of FORGE_REPO. | |
| 578 | // The live release and the kept ones, as /releases gates them: a site admin or a reader of | |
| 579 | // FORGE_REPO. | |
| 576 | 580 | if (mayRead(session.app, session.user)) |
| 577 | 581 | commands.push({ |
| 578 | 582 | id: "releases", |
| @@ -620,7 +624,8 @@ export function forgeCommands(session: Session): (ctx: Ctx) => Command[] { | ||
| 620 | 624 | hint: "internal hosts an origin may reach", |
| 621 | 625 | run: () => ctx.push(trustedHostsPrompt(session, ctx, blank("Trusted hosts"))), |
| 622 | 626 | }); |
| 623 | // Usage: the forge's spend for any signed-in user (#8308); the route list stays the page's gate, the same as Flags (#1565). | |
| 627 | // Usage: the forge's spend for any signed-in user (#8308); the route list stays the page's | |
| 628 | // gate, the same as Flags (#1565). | |
| 624 | 629 | if (session.user !== undefined) |
| 625 | 630 | commands.push({ |
| 626 | 631 | id: "usage", |
| @@ -652,7 +657,8 @@ export function forgeCommands(session: Session): (ctx: Ctx) => Command[] { | ||
| 652 | 657 | hint: "what your crew may spend, and add your own subscription", |
| 653 | 658 | run: () => ctx.push(modelScreen(session, ctx)), |
| 654 | 659 | }); |
| 655 | // The caller's own role and row of the roles table, as /settings and `whoami_can` have it (#2304). | |
| 660 | // The caller's own role and row of the roles table, as /settings and `whoami_can` have it | |
| 661 | // (#2304). | |
| 656 | 662 | if (session.user !== undefined) |
| 657 | 663 | commands.push({ |
| 658 | 664 | id: "can", |
| @@ -662,6 +668,13 @@ export function forgeCommands(session: Session): (ctx: Ctx) => Command[] { | ||
| 662 | 668 | }); |
| 663 | 669 | // Entries that live beside their screen, each at the place it names. |
| 664 | 670 | addEntries(commands, session, ctx); |
| 671 | // What /security says, for anyone (#13208). | |
| 672 | commands.push({ | |
| 673 | id: "security", | |
| 674 | title: "Security", | |
| 675 | hint: "what the forge enforces for everyone, and how to report a problem", | |
| 676 | run: () => ctx.push(securityScreen(ctx)), | |
| 677 | }); | |
| 665 | 678 | commands.push({ |
| 666 | 679 | id: "family", |
| 667 | 680 | title: "Family", |
src/tui/screens/security_public.ts added +60
| @@ -0,0 +1,60 @@ | ||
| 1 | /** | |
| 2 | * Security in the terminal (#13208): the same claims /security shows, from | |
| 3 | * `view/security.ts`, as scrolling lines. Offered to everyone, signed in or | |
| 4 | * not, like the page. Read-only. | |
| 5 | */ | |
| 6 | ||
| 7 | import { CLAIMS, REPORT_CLAIMS, SECURITY_PURPOSE, type Claim } from "../../view/security.ts"; | |
| 8 | import type { Ctx, Screen } from "../app/app.ts"; | |
| 9 | import { binding } from "../app/keys.ts"; | |
| 10 | import { BOLD, style } from "../term/style.ts"; | |
| 11 | import { wrap } from "../term/width.ts"; | |
| 12 | import { Scroll, drawLines, hitScroll } from "./common.ts"; | |
| 13 | ||
| 14 | type Line = { text: string; kind: "head" | "label" | "body" | "muted" }; | |
| 15 | ||
| 16 | /** The screen's lines at a width: plain data, so a test reads what a person reads. */ | |
| 17 | export function securityLines(width: number): Line[] { | |
| 18 | const w = Math.max(20, width); | |
| 19 | const out: Line[] = []; | |
| 20 | const para = (text: string, kind: Line["kind"]) => { | |
| 21 | for (const t of wrap(text, w)) out.push({ text: t, kind }); | |
| 22 | }; | |
| 23 | const claim = (c: Claim) => { | |
| 24 | out.push({ text: c.what, kind: "label" }); | |
| 25 | para(` ${c.words}`, "body"); | |
| 26 | para(` Enforced in ${c.source}.`, "muted"); | |
| 27 | }; | |
| 28 | para(SECURITY_PURPOSE, "body"); | |
| 29 | out.push({ text: "", kind: "body" }, { text: "Enforced for everyone, with no setting", kind: "head" }); | |
| 30 | CLAIMS.forEach(claim); | |
| 31 | out.push({ text: "", kind: "body" }, { text: "Report a problem", kind: "head" }); | |
| 32 | para("A vulnerability: tell the contact in /.well-known/security.txt on this forge.", "body"); | |
| 33 | REPORT_CLAIMS.forEach(claim); | |
| 34 | return out; | |
| 35 | } | |
| 36 | ||
| 37 | export function securityScreen(ctx: Ctx): Screen { | |
| 38 | const scroll = new Scroll(); | |
| 39 | let count = 0; | |
| 40 | return { | |
| 41 | title: "Security", | |
| 42 | keys: [binding(["j", "k"], "scroll"), binding(["esc", "q"], "back")], | |
| 43 | render(area, s) { | |
| 44 | const c = ctx.theme.c; | |
| 45 | const tone = { head: style(c.fg, c.bg, BOLD), label: style(c.fg, c.bg, BOLD), body: style(c.fg, c.bg), muted: style(c.mutedFg, c.bg) }; | |
| 46 | const lines = securityLines(area.w - 2); | |
| 47 | count = lines.length; | |
| 48 | drawLines(s, area, c, scroll, lines.map((l) => [{ text: l.text, style: tone[l.kind] }])); | |
| 49 | hitScroll(ctx, area, scroll, count); | |
| 50 | }, | |
| 51 | key(e) { | |
| 52 | if (scroll.key(e, count)) return true; | |
| 53 | if (e.key === "esc" || e.key === "q") { | |
| 54 | ctx.pop(); | |
| 55 | return true; | |
| 56 | } | |
| 57 | return false; | |
| 58 | }, | |
| 59 | }; | |
| 60 | } |
src/view/security.ts added +110
| @@ -0,0 +1,110 @@ | ||
| 1 | /** | |
| 2 | * What /security says (#13208), as plain data the page and the terminal screen | |
| 3 | * both draw: each claim names the file that enforces it and the test that | |
| 4 | * proves it, and test/security-page.test.ts checks both still stand, so a claim | |
| 5 | * cannot outlive its behaviour. | |
| 6 | */ | |
| 7 | ||
| 8 | import { REFUSED_PREFIX } from "../apps/egress.ts"; | |
| 9 | ||
| 10 | /** One thing the forge does for every app and every visitor, with no setting to turn it on. */ | |
| 11 | export interface Claim { | |
| 12 | /** The row's label: what is kept safe, in a word or two. */ | |
| 13 | what: string; | |
| 14 | /** The sentence a visitor reads. */ | |
| 15 | words: string; | |
| 16 | /** The file that enforces it, from the repository root. */ | |
| 17 | source: string; | |
| 18 | /** Text that file must still contain for the sentence to stay true. */ | |
| 19 | needle: string; | |
| 20 | /** The test that proves the behaviour. */ | |
| 21 | proof: string; | |
| 22 | } | |
| 23 | ||
| 24 | export const CLAIMS: readonly Claim[] = [ | |
| 25 | { | |
| 26 | what: "Outside hosts", | |
| 27 | words: `An app reaches only the hosts its forge.json egress names; any other is refused with a 403 that says "${REFUSED_PREFIX} <host> is not in this app's forge.json egress".`, | |
| 28 | source: "src/apps/egress.ts", | |
| 29 | needle: "is not in this app's forge.json egress", | |
| 30 | proof: "test/egress-refused.test.ts", | |
| 31 | }, | |
| 32 | { | |
| 33 | what: "Repository code", | |
| 34 | words: | |
| 35 | "An app, its preview, its terminal and every install and test step run in a cell of their own: the machine is read-only to them, they see no other process, and the forge's proxy is their only way out.", | |
| 36 | source: "src/apps/contain.ts", | |
| 37 | needle: "bubblewrap", | |
| 38 | proof: "test/contain.test.ts", | |
| 39 | }, | |
| 40 | { | |
| 41 | what: "Agents", | |
| 42 | words: | |
| 43 | "An agent's shell reaches the forge, the package registry and its own app, writes only in its own clone, and cannot read the forge's data, keys or other agents' work.", | |
| 44 | source: "src/crew/sandbox.ts", | |
| 45 | needle: "export function sandboxPolicy", | |
| 46 | proof: "test/crew-sandbox.test.ts", | |
| 47 | }, | |
| 48 | { | |
| 49 | what: "Weaker machines", | |
| 50 | words: | |
| 51 | "Where a machine cannot hold a cell or a sandbox, the forge still runs and says so to its admin at the foot of every page.", | |
| 52 | source: "src/kernel/protection.ts", | |
| 53 | needle: "export function protectionNotice", | |
| 54 | proof: "test/protection.test.ts", | |
| 55 | }, | |
| 56 | { | |
| 57 | what: "Your sign-in", | |
| 58 | words: | |
| 59 | "It lives in a cookie scripts cannot read (HttpOnly), other sites cannot send (SameSite=Lax), and that travels only over https when the forge is served over https (Secure).", | |
| 60 | source: "src/auth/cookies.ts", | |
| 61 | needle: '"HttpOnly", "SameSite=Lax"', | |
| 62 | proof: "test/cookie-flags.test.ts", | |
| 63 | }, | |
| 64 | { | |
| 65 | what: "Changes from other sites", | |
| 66 | words: | |
| 67 | "A POST, PUT, PATCH or DELETE your browser sends from another site with your sign-in is refused before any code acts on it.", | |
| 68 | source: "src/http/origin_gate.ts", | |
| 69 | needle: 'new Set(["POST", "PUT", "PATCH", "DELETE"])', | |
| 70 | proof: "test/origin-every-mutation.test.ts", | |
| 71 | }, | |
| 72 | { | |
| 73 | what: "Every answer", | |
| 74 | words: | |
| 75 | "It tells your browser not to guess its type (nosniff) and not to send the address you were on to another site (Referrer-Policy: same-origin).", | |
| 76 | source: "src/http/respond.ts", | |
| 77 | needle: "export function securityFloor", | |
| 78 | proof: "test/security-floor-every-route.test.ts", | |
| 79 | }, | |
| 80 | ]; | |
| 81 | ||
| 82 | /** The ways to tell someone about a problem; the security contact is drawn beside them. */ | |
| 83 | export const REPORT_CLAIMS: readonly Claim[] = [ | |
| 84 | { | |
| 85 | what: "Sealed report", | |
| 86 | words: | |
| 87 | 'In a repository here, open an issue and tick "Sealed security report": only people who can write there and its crew see it, until one of them unseals it.', | |
| 88 | source: "src/core/sealed.ts", | |
| 89 | needle: "export function canSeeSealed", | |
| 90 | proof: "test/sealed-issues.test.ts", | |
| 91 | }, | |
| 92 | { | |
| 93 | what: "A repository", | |
| 94 | words: "Any public repository takes a report at /<owner>/<name>/report, with no account.", | |
| 95 | source: "src/http/server.ts", | |
| 96 | needle: 'router.add("GET", "/:owner/:name/report", reportPage)', | |
| 97 | proof: "test/reports.test.ts", | |
| 98 | }, | |
| 99 | { | |
| 100 | what: "An app", | |
| 101 | words: "Every public app takes one at /__forge/report on its own address, even while the app is down.", | |
| 102 | source: "src/apps/proxy.ts", | |
| 103 | needle: 'url.pathname === "/__forge/report"', | |
| 104 | proof: "test/apps-report.test.ts", | |
| 105 | }, | |
| 106 | ]; | |
| 107 | ||
| 108 | /** The page's opening sentence, said once on both surfaces. */ | |
| 109 | export const SECURITY_PURPOSE = | |
| 110 | "What this forge enforces for every app and visitor without a setting, and how to report a problem without an account."; |
src/web/layout.ts +2
| @@ -754,6 +754,8 @@ function footer(ctx: Ctx, own?: Html): Html { | ||
| 754 | 754 | <span class="spacer"></span> |
| 755 | 755 | <a href="/docs">Docs</a> |
| 756 | 756 | <a href="/pricing">Pricing</a> |
| 757 | <a href="/privacy">Privacy</a> | |
| 758 | <a href="/security">Security</a> | |
| 757 | 759 | <a href="/changelog">Changelog</a> |
| 758 | 760 | <a href="/api">API</a> |
| 759 | 761 | ${ctx.auth.user !== undefined && ctx.auth.user.kind !== "org" |
src/web/pages/docs_link.ts +7 −3
| @@ -20,7 +20,10 @@ import { row } from "../ui.ts"; | ||
| 20 | 20 | |
| 21 | 21 | const rendered = new Map<string, string>(); |
| 22 | 22 | |
| 23 | /** `OTHER.md` and `./OTHER.md` (with an anchor) become `/docs/OTHER.md` when OTHER.md is in the listing; any other link stays as written. */ | |
| 23 | /** | |
| 24 | * `OTHER.md` and `./OTHER.md` (with an anchor) become `/docs/OTHER.md` when OTHER.md is in the | |
| 25 | * listing; any other link stays as written. | |
| 26 | */ | |
| 24 | 27 | export function relinkDocs(markup: string, known: ReadonlySet<string> = new Set([...docEntries(), ...featureEntries()].map((e) => e.name))): string { |
| 25 | 28 | return markup.replace( |
| 26 | 29 | /href="(?:\.\/)?((?:features\/)?[A-Za-z0-9][A-Za-z0-9._-]{0,80}\.md)(#[^"]*)?"/g, |
| @@ -72,7 +75,7 @@ export function docsFolder(ctx: Ctx): Response { | ||
| 72 | 75 | } else { |
| 73 | 76 | const { guide: spine, rest } = docSpine(); |
| 74 | 77 | body = html`<h1>Documentation</h1>${form} |
| 75 | <h2>Start here: the guide, one screen or two a page</h2> | |
| 78 | <h2>Start here: the guide</h2> | |
| 76 | 79 | <ol class="list docs-index">${spine.map(indexRow)}</ol> |
| 77 | 80 | <h2>Reference</h2> |
| 78 | 81 | <ul class="list docs-index">${rest.map(indexRow)}</ul>`; |
| @@ -110,7 +113,8 @@ function docPage(ctx: Ctx, name: string, began: number): Response { | ||
| 110 | 113 | markup = relinkDocs(anchorHeadings(String(renderMarkdown(text)))); |
| 111 | 114 | rendered.set(name, markup); |
| 112 | 115 | } |
| 113 | // The link to a sibling folder's file depends on whether this forge holds the upstream repository, so it is made per request. | |
| 116 | // The link to a sibling folder's file depends on whether this forge holds the upstream | |
| 117 | // repository, so it is made per request. | |
| 114 | 118 | const body = raw(`<div class="prose">${relinkFolderDocs(markup, ctx.app.db)}</div>`); |
| 115 | 119 | const res = page({ |
| 116 | 120 | ctx, |
src/web/pages/security_public.ts added +56
| @@ -0,0 +1,56 @@ | ||
| 1 | /** | |
| 2 | * GET /security (#13208): how the forge keeps a visitor safe and how to tell | |
| 3 | * someone about a problem, in plain words — /.well-known/security.txt for | |
| 4 | * people. Public, static, server-rendered in the shared layout. Each claim | |
| 5 | * is a `status-rows` row (what, then the sentence and the file that enforces | |
| 6 | * it); the claims are plain data in `view/security.ts`, which the terminal's | |
| 7 | * Security screen draws too. (/settings/security, the admin's page, is | |
| 8 | * `security.ts`.) | |
| 9 | */ | |
| 10 | ||
| 11 | import { publicForgeRepo } from "../../core/forge_repo.ts"; | |
| 12 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; | |
| 13 | import type { Ctx } from "../../http/context.ts"; | |
| 14 | import { CLAIMS, REPORT_CLAIMS, SECURITY_PURPOSE, type Claim } from "../../view/security.ts"; | |
| 15 | import { html, type Html } from "../html.ts"; | |
| 16 | import { page } from "../layout.ts"; | |
| 17 | import { securityContact } from "../standards.ts"; | |
| 18 | ||
| 19 | function claimRow(c: Claim): Html { | |
| 20 | return html`<div class="status-row"> | |
| 21 | <dt>${c.what}</dt> | |
| 22 | <dd>${c.words} <span class="small muted">Enforced in <code>${c.source}</code>.</span></dd> | |
| 23 | </div>`; | |
| 24 | } | |
| 25 | ||
| 26 | /** The contact as a row: a link only when it is http(s), else plain text. */ | |
| 27 | function contactRow(contact: string): Html { | |
| 28 | const shown = /^https?:\/\//.test(contact) | |
| 29 | ? html`<a href="${contact}">${contact}</a>` | |
| 30 | : html`<code>${contact}</code>`; | |
| 31 | return html`<div class="status-row"> | |
| 32 | <dt>A vulnerability</dt> | |
| 33 | <dd>Tell ${shown}. Machines read the same at <a href="/.well-known/security.txt">/.well-known/security.txt</a>.</dd> | |
| 34 | </div>`; | |
| 35 | } | |
| 36 | ||
| 37 | /** The page's body: plain data in (the contact), escaped HTML out. */ | |
| 38 | export function securityBody(contact: string): Html { | |
| 39 | return html`<div class="page-head"><h1>Security</h1></div> | |
| 40 | <p class="mb">${SECURITY_PURPOSE}</p> | |
| 41 | <h2>Enforced for everyone, with no setting</h2> | |
| 42 | <dl class="status-rows">${CLAIMS.map(claimRow)}</dl> | |
| 43 | <h2>Report a problem</h2> | |
| 44 | <dl class="status-rows">${contactRow(contact)}${REPORT_CLAIMS.map(claimRow)}</dl>`; | |
| 45 | } | |
| 46 | ||
| 47 | export function publicSecurityPage(ctx: Ctx): Response { | |
| 48 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 49 | return timePhase(ctx.request, "render", () => | |
| 50 | page({ | |
| 51 | ctx, | |
| 52 | title: "Security", | |
| 53 | body: securityBody(securityContact(ctx, publicForgeRepo(ctx.app))), | |
| 54 | }), | |
| 55 | ); | |
| 56 | } |
src/web/standards.ts +1 −1
| @@ -78,7 +78,7 @@ function text(body: string, type = "text/plain; charset=utf-8"): Response { | ||
| 78 | 78 | * page on this forge — already public, and a real way to reach whoever |
| 79 | 79 | * runs it. |
| 80 | 80 | */ |
| 81 | function securityContact(ctx: Ctx, own: Repo | undefined): string { | |
| 81 | export function securityContact(ctx: Ctx, own: Repo | undefined): string { | |
| 82 | 82 | const configured = process.env["FORGE_SECURITY_CONTACT"]?.trim(); |
| 83 | 83 | if (configured) return configured; |
| 84 | 84 | if (own !== undefined) |
test/forge-looks.test.ts +1
| @@ -37,6 +37,7 @@ const NOT_A_PAGE: Record<string, string> = { | ||
| 37 | 37 | "/family": "no picture: its slot went to the preview's /waves and /milestones; the page is covered by its own tests", |
| 38 | 38 | "/llms.txt": "plain markdown for machines, not a page to picture", |
| 39 | 39 | "/agents": "/llms.txt drawn as a page for an assistant; no picture: not in app.looks, and test/agents-page.test.ts covers it", |
| 40 | "/map": "no picture: its slot went to /security, the visitor's security page (#13208); covered by test/map-cache.test.ts and the other map tests", | |
| 40 | 41 | "/packs": "no picture: not in app.looks; the page is covered by test/packs.test.ts", |
| 41 | 42 | "/fleet": "no picture: not in app.looks; the page is covered by test/fleet-table.test.ts", |
| 42 | 43 | "/robots.txt": "plain text for crawlers", |
test/palette-roster.test.ts +4
| @@ -212,6 +212,7 @@ test("a site-admin person is offered the whole roster", () => { | ||
| 212 | 212 | ["origin-ahead", "New commits upstream", "mirrors whose origin has moved on: take them"], |
| 213 | 213 | ["profile", "Your profile", "display name and email"], |
| 214 | 214 | ["dotfiles", "Your dotfiles", "the repository every shell you open copies from"], |
| 215 | ["security", "Security", "what the forge enforces for everyone, and how to report a problem"], | |
| 215 | 216 | ["family", "Family", "the forge that sent this one, and the forges it sent"], |
| 216 | 217 | ["chain", "Chain", "the forges this forge's code descends from, root first"], |
| 217 | 218 | ["quit", "Quit", "disconnect"], |
| @@ -303,6 +304,7 @@ test("a site-admin agent is offered the roster without the person-only entries", | ||
| 303 | 304 | ["origin-ahead", "New commits upstream", "mirrors whose origin has moved on: take them"], |
| 304 | 305 | ["front-milestones", "Milestones", "the biggest open milestones: how far, what landed this week"], |
| 305 | 306 | ["forge-view", "Forge view", "the forge's counts, and Foundry when it is installed"], |
| 307 | ["security", "Security", "what the forge enforces for everyone, and how to report a problem"], | |
| 306 | 308 | ["family", "Family", "the forge that sent this one, and the forges it sent"], |
| 307 | 309 | ["chain", "Chain", "the forges this forge's code descends from, root first"], |
| 308 | 310 | ["quit", "Quit", "disconnect"], |
| @@ -399,6 +401,7 @@ test("a member person is offered the signed-in roster without the admin entries" | ||
| 399 | 401 | ["dotfiles", "Your dotfiles", "the repository every shell you open copies from"], |
| 400 | 402 | ["front-milestones", "Milestones", "the biggest open milestones: how far, what landed this week"], |
| 401 | 403 | ["forge-view", "Forge view", "the forge's counts, and Foundry when it is installed"], |
| 404 | ["security", "Security", "what the forge enforces for everyone, and how to report a problem"], | |
| 402 | 405 | ["family", "Family", "the forge that sent this one, and the forges it sent"], |
| 403 | 406 | ["chain", "Chain", "the forges this forge's code descends from, root first"], |
| 404 | 407 | ["quit", "Quit", "disconnect"], |
| @@ -449,6 +452,7 @@ test("signed out, the palette offers sign-in and the public entries", () => { | ||
| 449 | 452 | ["front", "Front page", "the apps a first visitor sees, ranked; an admin pins or hides"], |
| 450 | 453 | ["origin-ahead", "New commits upstream", "mirrors whose origin has moved on: take them"], |
| 451 | 454 | ["front-milestones", "Milestones", "the biggest open milestones: how far, what landed this week"], |
| 455 | ["security", "Security", "what the forge enforces for everyone, and how to report a problem"], | |
| 452 | 456 | ["family", "Family", "the forge that sent this one, and the forges it sent"], |
| 453 | 457 | ["chain", "Chain", "the forges this forge's code descends from, root first"], |
| 454 | 458 | ["quit", "Quit", "disconnect"], |
test/security-page.test.ts added +92
| @@ -0,0 +1,92 @@ | ||
| 1 | /** | |
| 2 | * GET /security (#13208): public, in the shared layout, linked from the foot, | |
| 3 | * each claim a row; every claim still stands on the file and test it names, | |
| 4 | * and the terminal's Security screen says the same. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 7 | import { existsSync, readFileSync } from "node:fs"; | |
| 8 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 9 | import { tmpdir } from "node:os"; | |
| 10 | import { join } from "node:path"; | |
| 11 | import { createApp, type App } from "../src/app.ts"; | |
| 12 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 13 | import { escapeHtml } from "../src/web/html.ts"; | |
| 14 | import { CLAIMS, REPORT_CLAIMS, SECURITY_PURPOSE } from "../src/view/security.ts"; | |
| 15 | import { securityBody } from "../src/web/pages/security_public.ts"; | |
| 16 | import { securityLines } from "../src/tui/screens/security_public.ts"; | |
| 17 | ||
| 18 | const root = join(import.meta.dir, ".."); | |
| 19 | let dir: string; | |
| 20 | let app: App; | |
| 21 | let servers: Servers; | |
| 22 | ||
| 23 | beforeAll(async () => { | |
| 24 | dir = await mkdtemp(join(tmpdir(), "forge-security-page-")); | |
| 25 | app = createApp({ dataDir: dir, port: 0 }); | |
| 26 | servers = await serve(app); | |
| 27 | }); | |
| 28 | afterAll(async () => { | |
| 29 | servers.stop(); | |
| 30 | app.close(); | |
| 31 | await rm(dir, { recursive: true, force: true }); | |
| 32 | }); | |
| 33 | ||
| 34 | test("signed out, /security answers 200 in the shared layout: one opening sentence, a row per claim, the security floor", async () => { | |
| 35 | const res = await fetch(`${servers.url}/security`); | |
| 36 | expect(res.status).toBe(200); | |
| 37 | const text = await res.text(); | |
| 38 | expect(text).toContain('class="topbar'); | |
| 39 | expect(text).toMatch(/<title>Security[^<]*<\/title>/); | |
| 40 | expect(text).toContain(`<p class="mb">${escapeHtml(SECURITY_PURPOSE)}</p>`); | |
| 41 | expect(res.headers.get("x-content-type-options")).toBe("nosniff"); | |
| 42 | expect(res.headers.get("referrer-policy")).toBe("same-origin"); | |
| 43 | expect(res.headers.get("content-security-policy")).toBeTruthy(); | |
| 44 | for (const c of [...CLAIMS, ...REPORT_CLAIMS]) { | |
| 45 | expect(text).toContain(`<dt>${escapeHtml(c.what)}</dt>`); | |
| 46 | expect(text).toContain(escapeHtml(c.words)); | |
| 47 | } | |
| 48 | expect(text).toContain('href="/.well-known/security.txt"'); | |
| 49 | }); | |
| 50 | ||
| 51 | test("the contact it names is security.txt's own", async () => { | |
| 52 | const txt = await (await fetch(`${servers.url}/.well-known/security.txt`)).text(); | |
| 53 | const contact = /^Contact: (.+)$/m.exec(txt)?.[1]; | |
| 54 | expect(contact).toBeDefined(); | |
| 55 | const page = await (await fetch(`${servers.url}/security`)).text(); | |
| 56 | expect(page).toContain(escapeHtml(contact!)); | |
| 57 | }); | |
| 58 | ||
| 59 | test("every claim's source still says what the claim leans on, and its proof exists", () => { | |
| 60 | expect(CLAIMS.length).toBeGreaterThanOrEqual(5); | |
| 61 | expect(REPORT_CLAIMS.map((c) => c.words).join(" ")).toContain("/__forge/report"); | |
| 62 | for (const c of [...CLAIMS, ...REPORT_CLAIMS]) { | |
| 63 | expect(readFileSync(join(root, c.source), "utf8")).toContain(c.needle); | |
| 64 | expect(existsSync(join(root, c.proof))).toBe(true); | |
| 65 | } | |
| 66 | // The cookie claim names flags the cookie test asserts. | |
| 67 | const cookieTest = readFileSync(join(root, "test/cookie-flags.test.ts"), "utf8"); | |
| 68 | for (const flag of ["HttpOnly", "SameSite", "Secure"]) expect(cookieTest).toContain(flag); | |
| 69 | }); | |
| 70 | ||
| 71 | test("a contact is escaped, and only an http(s) one becomes a link", () => { | |
| 72 | const evil = securityBody('mailto:a@b"><x>').text; | |
| 73 | expect(evil).not.toContain("<x>"); | |
| 74 | expect(evil).not.toContain('href="mailto'); | |
| 75 | expect(securityBody("https://f.example/sec").text).toContain('href="https://f.example/sec"'); | |
| 76 | }); | |
| 77 | ||
| 78 | test("the foot of a shared page links /security beside /privacy", async () => { | |
| 79 | const text = await (await fetch(`${servers.url}/pricing`)).text(); | |
| 80 | expect(text).toMatch(/<a href="\/privacy">Privacy<\/a>\s*<a href="\/security">Security<\/a>/); | |
| 81 | }); | |
| 82 | ||
| 83 | test("the terminal's Security screen carries every claim, wrapped to its width", () => { | |
| 84 | const lines = securityLines(60); | |
| 85 | for (const l of lines) expect(l.text.length).toBeLessThanOrEqual(60); | |
| 86 | const joined = lines.map((l) => l.text.trim()).join(" "); | |
| 87 | expect(joined).toContain(SECURITY_PURPOSE); | |
| 88 | for (const c of [...CLAIMS, ...REPORT_CLAIMS]) { | |
| 89 | expect(lines.some((l) => l.kind === "label" && l.text === c.what)).toBe(true); | |
| 90 | expect(joined).toContain(c.words); | |
| 91 | } | |
| 92 | }); |
new above
offline