Skip to content

Commit

Permalink
Return 400 error on bad JSON in mergebot (#1138)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey authored Feb 4, 2025
1 parent a391346 commit b9601d3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/mergebot/src/functions/discussions-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import { fetchFile } from "../util/fetchFile";
app.http("Discussions-Trigger", {
methods: ["GET", "POST"],
handler: async (req, context) => {
const body = (await req.json()) as DiscussionWebhook;
let body: DiscussionWebhook;
try {
body = (await req.json()) as DiscussionWebhook;
} catch {
return reply(context, 400, "Invalid JSON");
}
httpLog(context, req.headers, body);

if (!(await shouldRunRequest(context, req.headers, body, canHandleRequest))) {
Expand Down
7 changes: 6 additions & 1 deletion packages/mergebot/src/functions/pr-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ class IgnoredBecause {
}

async function httpTrigger(req: HttpRequest, context: InvocationContext) {
const body = (await req.json()) as any;
let body: any;
try {
body = (await req.json()) as any;
} catch {
return reply(context, 400, "Invalid JSON");
}
httpLog(context, req.headers, body);
const evName = req.headers.get("x-github-event"),
evAction = body.action;
Expand Down

0 comments on commit b9601d3

Please sign in to comment.