Public: anyone can read this; the crew can change it.
/.well-known/security.txt and /robots.txt say where an outsider files a report or offers a pull #14495
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/14484-well-known-security-txt-and-robots-txt-s → main 5 commits fork 2 threads · 2 unresolved
2 files
changed +41
−23
src/web/standards.ts +34 −22
| @@ -68,9 +68,17 @@ import { shippedReleases, type Shipped } from "../release/shipped.ts"; | ||
| 68 | 68 | |
| 69 | 69 | const DAY = 24 * 60 * 60 * 1000; |
| 70 | 70 | |
| 71 | function text(body: string, type = "text/plain; charset=utf-8"): Response { | |
| 71 | /** | |
| 72 | * What the forge sends for its static-text metadata (security.txt, robots.txt): one day, longer | |
| 73 | * than the other answers here (an hour). The edge in front may rewrite a public max-age to its own | |
| 74 | * browser TTL (4 hours seen on production), so this is what the forge asks for, not a promise of | |
| 75 | * what a client sees. Far inside security.txt's Expires (150 days or more ahead). | |
| 76 | */ | |
| 77 | export const STATIC_TEXT_CACHE = "public, max-age=86400"; | |
| 78 | ||
| 79 | function text(body: string, type = "text/plain; charset=utf-8", cache = "public, max-age=3600"): Response { | |
| 72 | 80 | return new Response(body, { |
| 73 | headers: { "content-type": type, "cache-control": "public, max-age=3600" }, | |
| 81 | headers: { "content-type": type, "cache-control": cache }, | |
| 74 | 82 | }); |
| 75 | 83 | } |
| 76 | 84 | |
| @@ -115,27 +123,29 @@ export function securityExpires(now: Date): string { | ||
| 115 | 123 | .replace(/\.\d{3}Z$/, "Z"); |
| 116 | 124 | } |
| 117 | 125 | |
| 118 | /** GET /.well-known/security.txt */ | |
| 126 | /** GET /.well-known/security.txt: static text, one cache lifetime. */ | |
| 119 | 127 | export function securityTxt(ctx: Ctx): Response { |
| 120 | const expires = securityExpires(new Date()); | |
| 121 | return text( | |
| 122 | [ | |
| 123 | `Contact: ${securityContact(ctx, publicForgeRepo(ctx.app))}`, | |
| 124 | `Expires: ${expires}`, | |
| 125 | "Preferred-Languages: en", | |
| 126 | `Canonical: ${ctx.url.origin}/.well-known/security.txt`, | |
| 127 | "", | |
| 128 | "# A security problem in a repository here? Open an issue there and", | |
| 129 | '# tick "Sealed security report" (/<owner>/<name>/issues/new?sealed=1):', | |
| 130 | "# only the people who keep it and its crew see it, and you can follow", | |
| 131 | "# it, until its fix is released.", | |
| 132 | "#", | |
| 133 | "# Not a vulnerability? Any public repository here takes a report", | |
| 134 | "# without an account at /<owner>/<name>/report; how, for people and", | |
| 135 | `# agents: ${ctx.url.origin}/llms.txt`, | |
| 136 | "", | |
| 137 | ].join("\n"), | |
| 138 | ); | |
| 128 | return text(securityBody(ctx, new Date()), undefined, STATIC_TEXT_CACHE); | |
| 129 | } | |
| 130 | ||
| 131 | function securityBody(ctx: Ctx, now: Date): string { | |
| 132 | return [ | |
| 133 | `Contact: ${securityContact(ctx, publicForgeRepo(ctx.app))}`, | |
| 134 | `Expires: ${securityExpires(now)}`, | |
| 135 | "Preferred-Languages: en", | |
| 136 | `Policy: ${ctx.url.origin}/security`, | |
| 137 | `Canonical: ${ctx.url.origin}/.well-known/security.txt`, | |
| 138 | "", | |
| 139 | "# A security problem in a repository here? Open an issue there and", | |
| 140 | '# tick "Sealed security report" (/<owner>/<name>/issues/new?sealed=1):', | |
| 141 | "# only the people who keep it and its crew see it, and you can follow", | |
| 142 | "# it, until its fix is released.", | |
| 143 | "#", | |
| 144 | "# Not a vulnerability? Any public repository here takes a report", | |
| 145 | "# without an account at /<owner>/<name>/report; how, for people and", | |
| 146 | `# agents: ${ctx.url.origin}/llms.txt`, | |
| 147 | "", | |
| 148 | ].join("\n"); | |
| 139 | 149 | } |
| 140 | 150 | |
| 141 | 151 | /** |
| @@ -303,6 +313,8 @@ export function robotsTxt(ctx: Ctx): Response { | ||
| 303 | 313 | `Sitemap: ${ctx.url.origin}/sitemap.xml`, |
| 304 | 314 | "", |
| 305 | 315 | ].join("\n"), |
| 316 | undefined, | |
| 317 | STATIC_TEXT_CACHE, | |
| 306 | 318 | ); |
| 307 | 319 | } |
| 308 | 320 |
test/standards.test.ts +7 −1
| @@ -21,7 +21,7 @@ import { forgetListings, listingBuilds } from "../src/core/listings.ts"; | ||
| 21 | 21 | import { createOrg, retireOrg } from "../src/core/orgs.ts"; |
| 22 | 22 | import { getRepo, moveArchived } from "../src/core/repos.ts"; |
| 23 | 23 | import { SITE_LINE } from "../src/web/site_line.ts"; |
| 24 | import { securityExpires } from "../src/web/standards.ts"; | |
| 24 | import { securityExpires, STATIC_TEXT_CACHE } from "../src/web/standards.ts"; | |
| 25 | 25 | import { serve, type Servers } from "../src/http/server.ts"; |
| 26 | 26 | |
| 27 | 27 | describe("what the open web expects", () => { |
| @@ -78,6 +78,12 @@ describe("what the open web expects", () => { | ||
| 78 | 78 | expect(ahead).toBeGreaterThanOrEqual(30); |
| 79 | 79 | expect(ahead).toBeLessThanOrEqual(365); |
| 80 | 80 | expect(body).toContain(`Canonical: ${base}/.well-known/security.txt`); |
| 81 | // The policy page is the forge's own /security (RFC 9116 Policy). | |
| 82 | expect(body).toContain(`Policy: ${base}/security\n`); | |
| 83 | expect(res.headers.get("cache-control")).toBe(STATIC_TEXT_CACHE); | |
| 84 | expect(STATIC_TEXT_CACHE).toBe("public, max-age=86400"); | |
| 85 | const robots = await fetch(`${base}/robots.txt`); | |
outdated
The preview serves /robots.txt with max-age=14400, not 3600, so this assertion does not describe what ships. Reconcile code and test, and use one cache lifetime for both files. |
||
| 86 | expect(robots.headers.get("cache-control")).toBe(STATIC_TEXT_CACHE); | |
| 81 | 87 | // An operator who wants an address published writes it down. |
| 82 | 88 | process.env["FORGE_SECURITY_CONTACT"] = "mailto:[email protected]"; |
| 83 | 89 | try { |
new above
offline
Good: Policy is the forge's own /security page. But the Contact line just above still comes from securityContact(), which reads the db on every request. Cache it per origin so the answer is a static-text answer (box 3).