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
11 changes: 11 additions & 0 deletions pm-stack/aggregator/src/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export interface CommentsFile {
}

const GH_REF = /^[\w.-]+\/[\w.-]+#\d+$/;
// Result URLs are rendered as link hrefs on the dashboard (#950):
// only https://github.com/ result links are storable — a stored
// javascript:/data: URL would render as a clickable script link.
const GH_RESULT_URL = /^https:\/\/github\.com\//;
const COMMENT_KINDS = new Set<DashCommentKind>(["message", "note", "github"]);

function commentRecordProblem(value: unknown): string | null {
Expand Down Expand Up @@ -352,6 +356,13 @@ export class CommentsStore {
throw new Error("github result cannot carry both a url and an error");
}
if (result.url) {
// #950: the stored githubUrl is rendered as a link href, so only
// https://github.com/ result URLs are accepted — anything else
// (javascript:, data:, http:, other hosts) is refused with the
// state unchanged (the endpoint maps the throw to a 400).
if (!GH_RESULT_URL.test(result.url)) {
throw new Error("github result url must start with https://github.com/");
}
if (c.githubState === "posted") {
// Posted is terminal. A repeat of the same url is an
// idempotent no-op; a different url is a conflicting
Expand Down
63 changes: 63 additions & 0 deletions pm-stack/aggregator/test/slice3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,43 @@ describe("dashboard comments", () => {
expect(landed?.githubState).toBe("posted");
});

test("github result urls outside https://github.com/ are refused with state unchanged (#950)", async () => {
const dir3 = mkdtempSync(join(tmpdir(), "agg-comments-url-"));
const store = new CommentsStore(join(dir3, "comments.json"));
const addGh = () =>
store.add({
objectRef: "gh:developing-today/code#950",
kind: "github",
author: agent,
body: "posting this",
githubRef: "developing-today/code#950",
});

// Every non-github.com scheme/host is refused on a pending
// comment, with no githubUrl stored and state unchanged.
const pending = await addGh();
for (const bad of [
"javascript:alert(document.domain)",
"data:text/html,<script>alert(1)</script>",
"http://github.com/developing-today/code/issues/950#issuecomment-1",
"https://evil-github.com/developing-today/code#1",
"https://git.xywcc.com.evil.com/#1",
]) {
await expect(store.markGithubResult(pending.id, { url: bad })).rejects.toThrow("https://github.com/");
const row = (await store.all()).find((c) => c.id === pending.id);
expect(row?.githubState).toBe("pending");
expect(row?.githubUrl).toBeUndefined();
}

// The real flow still works: an https://github.com/ result URL
// is recorded and the comment posts.
const ok = await store.markGithubResult(pending.id, {
url: "https://github.com/developing-today/code/issues/950#issuecomment-1",
});
expect(ok?.githubState).toBe("posted");
expect(ok?.githubUrl).toBe("https://github.com/developing-today/code/issues/950#issuecomment-1");
});

test("a repeat report after a failed persist still lands the result on disk (#1686)", async () => {
// Codex P2 on PR 3062: markGithubResult flips the in-memory state
// before persist() runs. If that write fails, a repeat report hit
Expand Down Expand Up @@ -763,6 +800,32 @@ describe("slice-3 routes", () => {
expect(discuss).toContain("Post as GitHub comment");
});

test("github-result endpoint refuses non-github.com urls with a 400 (#950)", async () => {
const post = (body: unknown) =>
fetch(`http://127.0.0.1:${port}/api/comments/github-result`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify(body),
});
const author = { kind: "drew", id: "drew", label: "Drew" };
const ref = "gh:developing-today/code#950";
const created = (await (
await fetch(`http://127.0.0.1:${port}/api/comments`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
objectRef: ref,
kind: "github",
author,
body: "for the issue",
githubRef: "developing-today/code#950",
}),
})
).json()) as { comment: { id: string } };
const bad = await post({ id: created.comment.id, url: "javascript:alert(document.domain)" });
expect(bad.status).toBe(400);
});

test("item page carries the dashboard comments form + kinds explainer", async () => {
const board = (await (await fetch(`http://127.0.0.1:${port}/api/board.json`)).json()) as {
board: { id: string }[];
Expand Down
Loading