Skip to content

Commit 40b4353

Browse files
only21milclaude
andauthored
fix(server): HEAD webhook probes no longer start agent runs (#25291)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 1cfd23e commit 40b4353

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

‎apps/server/src/scheduledTasks/webhookRoute.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,32 @@ describe("webhook route", () => {
249249
}
250250
});
251251

252+
it("refuses HEAD probes without triggering the hook", async () => {
253+
let calls = 0;
254+
const { handler, dispose } = handlerFor(() => {
255+
calls += 1;
256+
return Effect.succeed({
257+
_tag: "accepted",
258+
deliveryId: ScheduledTaskWebhookDeliveryId.make("delivery:1"),
259+
outcome: "accepted",
260+
});
261+
});
262+
try {
263+
const response = await handler(
264+
new Request("http://env.local/api/hooks/id/tok", { method: "HEAD" }),
265+
);
266+
expect(response.status).toBe(405);
267+
expect(response.headers.get("allow")).toBe("GET, POST, PUT, PATCH");
268+
expect(response.headers.get("x-t3-hook-outcome")).toBe("method_not_allowed");
269+
expect(calls).toBe(0);
270+
const get = await handler(new Request("http://env.local/api/hooks/id/tok"));
271+
expect(get.status).toBe(202);
272+
expect(calls).toBe(1);
273+
} finally {
274+
await dispose();
275+
}
276+
});
277+
252278
it("hides service failures and defects behind a fixed 500", async () => {
253279
const failures = [
254280
Effect.fail(new ScheduledTaskError({ message: "database locked" })),

‎apps/server/src/scheduledTasks/webhookRoute.ts‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,16 @@ export const WEBHOOK_MAX_BODY_BYTES = 1024 * 1024;
2020
// The relay records this outcome header.
2121
const WEBHOOK_OUTCOME_HEADER = "x-t3-hook-outcome";
2222

23-
const json = (status: number, body: Record<string, string>, outcome: string) =>
24-
HttpServerResponse.jsonUnsafe(body, { status, headers: { [WEBHOOK_OUTCOME_HEADER]: outcome } });
23+
const json = (
24+
status: number,
25+
body: Record<string, string>,
26+
outcome: string,
27+
headers?: Record<string, string>,
28+
) =>
29+
HttpServerResponse.jsonUnsafe(body, {
30+
status,
31+
headers: { ...headers, [WEBHOOK_OUTCOME_HEADER]: outcome },
32+
});
2533

2634
export const layer = HttpApiBuilder.group(
2735
EnvironmentHttpApi,
@@ -41,6 +49,12 @@ export const layer = HttpApiBuilder.group(
4149
readonly params: { readonly hookId: string; readonly token: string };
4250
readonly request: HttpServerRequest.HttpServerRequest;
4351
}) {
52+
// The router answers HEAD with the GET route; link checkers probe with HEAD.
53+
if (request.method === "HEAD") {
54+
return json(405, { error: "method_not_allowed" }, "method_not_allowed", {
55+
allow: "GET, POST, PUT, PATCH",
56+
});
57+
}
4458
const contentLength = Number(request.headers["content-length"] ?? "0");
4559
if (!Number.isFinite(contentLength) || contentLength > WEBHOOK_MAX_BODY_BYTES) {
4660
return json(413, { error: "body_too_large" }, "body_too_large");

0 commit comments

Comments
 (0)