diff --git a/pm-stack/aggregator/src/server.ts b/pm-stack/aggregator/src/server.ts index 6c4be54aef..990f885210 100644 --- a/pm-stack/aggregator/src/server.ts +++ b/pm-stack/aggregator/src/server.ts @@ -57,6 +57,7 @@ import { identitiesFromRecords } from "./registry.ts"; import { attentionFragment, attentionSections, + esc, ghObjectRef, renderAa, renderAttention, @@ -1187,7 +1188,7 @@ async function handler(req: Request): Promise { const svc = usage.services.find((s) => s.id === serviceMatch[1]); if (svc) return html(renderServiceDetail(svc, usage.history[svc.id] ?? [], prov(), provDetail())); return html( - `

Not found

no SaaS service with id ${serviceMatch[1]} — back to Usage & billing

`, + `

Not found

no SaaS service with id ${esc(serviceMatch[1])} — back to Usage & billing

`, 404, ); } @@ -1370,7 +1371,7 @@ async function handler(req: Request): Promise { const config = projectConfigById(programProjectMatch[1]); if (!config) { return html( - `

Not found

no project with id ${programProjectMatch[1]} in the registry (src/project-config.ts) — back to the projects index

`, + `

Not found

no project with id ${esc(programProjectMatch[1])} in the registry (src/project-config.ts) — back to the projects index

`, 404, ); } @@ -1774,7 +1775,7 @@ async function handler(req: Request): Promise { return html(renderItem(title, id, links, items, comments, prov(), extras)); } return html( - `

Not found

no board item or roadmap row with subject ${id}

`, + `

Not found

no board item or roadmap row with subject ${esc(id)}

`, 404, ); } diff --git a/pm-stack/aggregator/test/error-boundary-1211.test.ts b/pm-stack/aggregator/test/error-boundary-1211.test.ts index 0bf8a06a26..124d51c2dd 100644 --- a/pm-stack/aggregator/test/error-boundary-1211.test.ts +++ b/pm-stack/aggregator/test/error-boundary-1211.test.ts @@ -81,6 +81,18 @@ describe("consistent not-found semantics over HTTP (#1211)", () => { expect(await svc.text()).toContain("Not found"); }); + test("unknown /item subjects with HTML metacharacters are returned as inert text", async () => { + const subject = `&`; + const item = await fetch(`http://127.0.0.1:${port}/item/${encodeURIComponent(subject)}`); + const body = await item.text(); + + expect(item.status).toBe(404); + expect(body).toContain( + `<img src=x onerror="alert(document.domain)">&`, + ); + expect(body).not.toContain(" { const page = await fetch(`http://127.0.0.1:${port}/no-such-page`); expect(page.status).toBe(404);