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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

torque/forge:torque/14484-well-known-security-txt-and-robots-txt-s → main 5 commits fork 2 threads · 2 unresolved

  • Merged. torque/14484-well-known-security-txt-and-robots-txt-s was merged into main as 8f0ae68.

Review

Sign in to review this change.
2 files changed +41 −23
src/web/standards.ts +34 −22
@@ -68,9 +68,17 @@ import { shippedReleases, type Shipped } from "../release/shipped.ts";
6868
6969 const DAY = 24 * 60 * 60 * 1000;
7070
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 {
7280 return new Response(body, {
73 headers: { "content-type": type, "cache-control": "public, max-age=3600" },
81 headers: { "content-type": type, "cache-control": cache },
7482 });
7583 }
7684
@@ -115,27 +123,29 @@ export function securityExpires(now: Date): string {
115123 .replace(/\.\d{3}Z$/, "Z");
116124 }
117125
118 /** GET /.well-known/security.txt */
126 /** GET /.well-known/security.txt: static text, one cache lifetime. */
outdated

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).

119127 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");
139149 }
140150
141151 /**
@@ -303,6 +313,8 @@ export function robotsTxt(ctx: Ctx): Response {
303313 `Sitemap: ${ctx.url.origin}/sitemap.xml`,
304314 "",
305315 ].join("\n"),
316 undefined,
317 STATIC_TEXT_CACHE,
306318 );
307319 }
308320
test/standards.test.ts +7 −1
@@ -21,7 +21,7 @@ import { forgetListings, listingBuilds } from "../src/core/listings.ts";
2121 import { createOrg, retireOrg } from "../src/core/orgs.ts";
2222 import { getRepo, moveArchived } from "../src/core/repos.ts";
2323 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";
2525 import { serve, type Servers } from "../src/http/server.ts";
2626
2727 describe("what the open web expects", () => {
@@ -78,6 +78,12 @@ describe("what the open web expects", () => {
7878 expect(ahead).toBeGreaterThanOrEqual(30);
7979 expect(ahead).toBeLessThanOrEqual(365);
8080 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);
8187 // An operator who wants an address published writes it down.
8288 process.env["FORGE_SECURITY_CONTACT"] = "mailto:[email protected]";
8389 try {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs