From 96eb00e98f10fdfaf76e0c0a600450e6d01a9c81 Mon Sep 17 00:00:00 2001 From: Zurva Aziz Date: Tue, 24 Nov 2026 13:44:57 -0800 Subject: [PATCH] fix(routines): prefer X-Hub-Signature-256 on app_webhook triggers (#18581) ## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Routines can start from public webhook triggers > - The `app_webhook` signing mode reads a signature from `X-Hub-Signature` or `X-Hub-Signature-256` > - Some senders, such as GitHub, can send both headers on one delivery > - The code reads `X-Hub-Signature` first, and `verifyAppWebhook` accepts only `sha256=` values > - So a SHA-1 value in `X-Hub-Signature` causes a 401, even when the SHA-256 signature is valid > - This pull request reads `X-Hub-Signature-256` first > - The benefit is that senders that send both headers can use `app_webhook` triggers ## Linked Issues or Issue Description Fixes #18565 Related, not duplicates: #16781, #1892. ## What Changed - `firePublicTrigger` now prefers `X-Hub-Signature-256` over `X-Hub-Signature` in `app_webhook` mode. - Added tests for both headers, each header alone, an invalid SHA-256 header, and a SHA-1 header alone. ## Verification - Codex ran these checks in its cloud sandbox. - Run from `server/`: `../node_modules/.bin/vitest run src/__tests__/routines-service.test.ts` - Result: 85 tests passed, 0 failed, 0 skipped. Embedded Postgres ran. - With the fix reversed, 2 of the 5 new tests failed. With the fix restored, all 5 passed. - The server TypeScript check passed. - The full workspace typecheck did not finish because `cargo` was not installed in the test environment. - The full build and the repository-wide tests were not run. CI must confirm them. ## Risks - Low risk. The change affects only `app_webhook` mode. - Behavior change: a delivery with a valid `sha256=` value in `X-Hub-Signature` and an invalid `X-Hub-Signature-256` value was accepted before. It now gets a 401. - SHA-1 signatures stay rejected. This is an interoperability fix, not a security fix. ## Model Used - Implementation and tests: OpenAI Codex (cloud). The session did not show the exact model ID, context window, or reasoning mode. - Review and pull request text: Anthropic Claude Opus 5.5 (`claude-opus-5-5`), with tool use. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [ ] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass (targeted suite only, in the Codex sandbox, see Verification) - [x] I have added or updated tests where applicable - [ ] I have updated relevant documentation to reflect my changes (not needed, the existing docs stay correct) - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [ ] I will address all Greptile and reviewer comments before requesting merge --- server/src/__tests__/routines-service.test.ts | 48 +++++++++++++++++++ server/src/services/routines.ts | 2 +- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/server/src/__tests__/routines-service.test.ts b/server/src/__tests__/routines-service.test.ts index 4a8718230cf..2c73797cc9c 100644 --- a/server/src/__tests__/routines-service.test.ts +++ b/server/src/__tests__/routines-service.test.ts @@ -2904,6 +2904,54 @@ describeEmbeddedPostgres("routine service live-execution coalescing", () => { }); + it.each([ + "both signature headers", + "SHA-256 header only", + "legacy header only", + ])("accepts a signed app webhook with %s", async (headers) => { + const { svc, routine, trigger, secretMaterial } = await firefliesFixture(false, "app_webhook"); + const payload = { event: "deployment.completed", deployment_id: "deploy-headers" }; + const rawBody = Buffer.from(JSON.stringify(payload)); + const secret = secretMaterial!.webhookSecret; + const signature = `sha256=${createHmac("sha256", secret).update(rawBody).digest("hex")}`; + const result = await svc.firePublicTrigger(trigger.publicId!, { + rawBody, + payload, + hubSignatureHeader: headers === "legacy header only" ? undefined : signature, + firefliesSignatureHeader: headers === "SHA-256 header only" + ? undefined + : headers === "legacy header only" + ? signature + : `sha1=${createHmac("sha1", secret).update(rawBody).digest("hex")}`, + }); + + expect(result.status).toBe("issue_created"); + const runs = await svc.listRuns(routine.id); + expect(runs).toHaveLength(1); + expect(runs[0].triggerPayload).toEqual(payload); + }); + + it.each(["invalid SHA-256 header", "SHA-1 header only"])( + "rejects an app webhook with %s despite valid bearer authorization", + async (headers) => { + const { svc, routine, trigger, secretMaterial } = await firefliesFixture(false, "app_webhook"); + const payload = { event: "deployment.completed", deployment_id: "deploy-invalid" }; + const rawBody = Buffer.from(JSON.stringify(payload)); + const secret = secretMaterial!.webhookSecret; + + await expect(svc.firePublicTrigger(trigger.publicId!, { + rawBody, + payload, + authorizationHeader: `Bearer ${secret}`, + hubSignatureHeader: headers === "SHA-1 header only" ? undefined : `sha256=${"0".repeat(64)}`, + firefliesSignatureHeader: headers === "SHA-1 header only" + ? `sha1=${createHmac("sha1", secret).update(rawBody).digest("hex")}` + : `sha256=${createHmac("sha256", secret).update(rawBody).digest("hex")}`, + })).rejects.toMatchObject({ status: 401 }); + expect(await svc.listRuns(routine.id)).toEqual([]); + }, + ); + it("dispatches one Fireflies run for concurrent retries and passes meeting metadata", async () => { const { svc, routine, trigger, delivery, wakeups } = await firefliesFixture(); const results = await Promise.all([ diff --git a/server/src/services/routines.ts b/server/src/services/routines.ts index 8b935241c49..b7c69a9233d 100644 --- a/server/src/services/routines.ts +++ b/server/src/services/routines.ts @@ -3319,7 +3319,7 @@ export function routineService( appDelivery = verifyAppWebhook({ secret: await resolveTriggerSecret(trigger, routine.companyId), publicId, authorization: input.authorizationHeader, - signature: input.firefliesSignatureHeader ?? input.hubSignatureHeader, + signature: input.hubSignatureHeader ?? input.firefliesSignatureHeader, rawBody: input.rawBody, idempotencyKey: input.idempotencyKey, }); } else if (trigger.signingMode === "fireflies_hmac") {