From fb2998a38729f2190cd282d87882b23abfbd3e8b Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 09:30:24 -0600 Subject: [PATCH] fix(pm-aggregator): escape unknown item subjects --- pm-stack/aggregator/src/server.ts | 7 ++++--- pm-stack/aggregator/test/error-boundary-1211.test.ts | 12 ++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pm-stack/aggregator/src/server.ts b/pm-stack/aggregator/src/server.ts index 3a82e4e97c..b0f7c79480 100644 --- a/pm-stack/aggregator/src/server.ts +++ b/pm-stack/aggregator/src/server.ts @@ -56,6 +56,7 @@ import { identitiesFromRecords } from "./registry.ts"; import { attentionFragment, attentionSections, + esc, ghObjectRef, renderAa, renderAttention, @@ -1040,7 +1041,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, ); } @@ -1223,7 +1224,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, ); } @@ -1612,7 +1613,7 @@ async function handler(req: Request): Promise { }; return html(renderItem(title, id, links, notes, items, comments, prov(), extras)); } - return html(`

Not found

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

`, 404); + return html(`

Not found

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

`, 404); } return notFoundResponse(path); 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);