Skip to content
Hidden Logic Lab

Review inbound webhooks: signature, replay, and idempotency

Run this on webhook PRs before merge. You verify raw-body signing first, then replay windows and durable event-id dedup before any billing or fulfillment side effect — not generic handler style.

Copy prompt

Cursor, Claude Code · Coding · 40 min · Working

Outcome

A PR comment with provider verify order, replay policy, idempotency storage, and HTTP status rules; merge blocked while signature or dedup gaps remain.

Steps

  1. 1

    Draw middleware order on paper

    Raw body capture must precede express.json() (or equivalent). If the diagram disagrees with the diff, Block before discussing event types.

  2. 2

    Replay one event twice

    Deliver the same signed payload twice in staging. The second run should be a no-op with idempotency metadata in logs — not a duplicate fulfillment.

  3. 3

    Align HTTP status with on-call

    Document when Stripe should retry (5xx) vs when bad signatures return 4xx. Mismatched status codes stop retries on real outages.

Copy prompt

The prompt to paste

Review this webhook PR for verify-then-process, replay tolerance, and idempotency before irreversible side effects.

Repository facts (fill before you start):
[webhook routes changed — paths only]
[providers: Stripe, Shopify, GitHub, Svix, custom HMAC — names only]
[signing secret env var NAMES only — never values]
[idempotency store: table or key pattern for processed event ids]
[which event types perform irreversible writes]

PR context:
[PR link or diff summary]
[sample event types in the diff]

Deliver a PR comment with these sections:

## Verify order
- Quote middleware/route order: is the raw body available before JSON parsers run?
- For each provider: header names, which bytes are signed, and whether verify uses the SDK or custom HMAC.
- Block if JSON is parsed or business logic runs before signature verification succeeds.

## Replay
- Timestamp or nonce checks per provider docs; max age and clock-skew allowance.
- Block if policy requires replay rejection but the diff removes or widens the window without a ticket.

## Idempotency (including Stripe retries)
- Where event.id (or equivalent) is persisted before side effects; unique constraint or lock.
- Block if duplicate delivery can run fulfillment, entitlements, or ledger writes twice.
- HTTP status policy: 4xx on bad signature; 5xx on retryable failure; 2xx only after idempotency record is durable (not after fire-and-forget).

## Findings table
[Block | Warn | Note] route — issue — one-line fix

Rules:
- Never paste signing secrets or full customer payloads.
- Do not propose disabling verify to unblock CI.
- If Stripe: confirm constructEvent (or equivalent) receives raw bytes, not re-stringified JSON.

Returning 200 before the idempotency row commits duplicates side effects on crash. Parsing JSON before constructEvent invalidates the signature on re-serialized bodies. Block those patterns even when the handler looks correct.

Sample case written by Hidden Logic Lab. Not affiliated with Cursor or Claude Code.

Get new cases in your inbox

Weekly notes on new use cases and agent workflows. No product pitches.

Occasional notes on new cases. No product pitches in the first note.