Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions pm-stack/aggregator/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import { identitiesFromRecords } from "./registry.ts";
import {
attentionFragment,
attentionSections,
esc,
ghObjectRef,
renderAa,
renderAttention,
Expand Down Expand Up @@ -1187,7 +1188,7 @@ async function handler(req: Request): Promise<Response> {
const svc = usage.services.find((s) => s.id === serviceMatch[1]);
if (svc) return html(renderServiceDetail(svc, usage.history[svc.id] ?? [], prov(), provDetail()));
return html(
`<h1>Not found</h1><p class="muted">no SaaS service with id <code>${serviceMatch[1]}</code> — <a href="/quota">back to Usage &amp; billing</a></p>`,
`<h1>Not found</h1><p class="muted">no SaaS service with id <code>${esc(serviceMatch[1])}</code> — <a href="/quota">back to Usage &amp; billing</a></p>`,
404,
);
}
Expand Down Expand Up @@ -1370,7 +1371,7 @@ async function handler(req: Request): Promise<Response> {
const config = projectConfigById(programProjectMatch[1]);
if (!config) {
return html(
`<h1>Not found</h1><p class="muted">no project with id <code>${programProjectMatch[1]}</code> in the registry (<code>src/project-config.ts</code>) — <a href="/program">back to the projects index</a></p>`,
`<h1>Not found</h1><p class="muted">no project with id <code>${esc(programProjectMatch[1])}</code> in the registry (<code>src/project-config.ts</code>) — <a href="/program">back to the projects index</a></p>`,
404,
);
}
Expand Down Expand Up @@ -1774,7 +1775,7 @@ async function handler(req: Request): Promise<Response> {
return html(renderItem(title, id, links, items, comments, prov(), extras));
}
return html(
`<h1>Not found</h1><p class="muted">no board item or roadmap row with subject <code>${id}</code></p>`,
`<h1>Not found</h1><p class="muted">no board item or roadmap row with subject <code>${esc(id)}</code></p>`,
404,
);
}
Expand Down
12 changes: 12 additions & 0 deletions pm-stack/aggregator/test/error-boundary-1211.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<img src=x onerror="alert(document.domain)">&`;
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(
`<code>&lt;img src=x onerror=&quot;alert(document.domain)&quot;&gt;&amp;</code>`,
);
expect(body).not.toContain("<img");
});

test("unknown page routes are styled HTML 404; unknown APIs are JSON 404", async () => {
const page = await fetch(`http://127.0.0.1:${port}/no-such-page`);
expect(page.status).toBe(404);
Expand Down