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
8 changes: 8 additions & 0 deletions pkgs/github-ci/worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ export default {
} catch {
return new Response("bad json", { status: 400 });
}
// #6946: JSON.parse also succeeds for null/array/scalar bodies, and
// dereferencing payload.repository on those threw out of fetch
// (outside the receiver-failed envelope below). A webhook payload
// is an object by contract; anything else is a deliberate 400 for
// every event type, before any dereference.
if (typeof payload !== "object" || payload === null || Array.isArray(payload)) {
return new Response("bad payload", { status: 400 });
}

const eventType = req.headers.get("x-github-event") ?? "workflow_run";
if (eventType === "ping") return new Response("pong", { status: 200 });
Expand Down
24 changes: 24 additions & 0 deletions pkgs/github-ci/worker/test/worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,30 @@ describe("github-ci worker", () => {
expect(res.status).toBe(401);
});

it("rejects a signed null body with 400 for workflow_run (#6946)", async () => {
const body = "null";
const res = await post(body, "workflow_run", await sign(body));
expect(res.status).toBe(400);
});

it("rejects a signed null body with 400 for push (#6946)", async () => {
const body = "null";
const res = await post(body, "push", await sign(body));
expect(res.status).toBe(400);
});

it("rejects a signed array body with 400 (#6946)", async () => {
const body = "[]";
const res = await post(body, "workflow_run", await sign(body));
expect(res.status).toBe(400);
});

it("rejects a signed scalar body with 400 (#6946)", async () => {
const body = "\"hello\"";
const res = await post(body, "push", await sign(body));
expect(res.status).toBe(400);
});

it("answers ping", async () => {
const body = JSON.stringify({ zen: "ok" });
const res = await post(body, "ping", await sign(body));
Expand Down
Loading