TEST WEBHOOK SIGNATURE VERIFICATION LOCALLY BEFORE DEPLOYING: TOOLS TO REPLAY SIGNED PAYLOADS

Test webhook signature verification locally before deploying: tools to replay signed payloads

Capture real signed deliveries, replay them against your localhost endpoint, and confirm your HMAC-SHA256 logic is correct before production traffic arrives — tunnels, inspection endpoints, curl replay commands, test vectors, and publisher test fires.

“I want to test webhook signature verification locally before deploying — what tools let me replay signed payloads against my local endpoint so I can confirm my HMAC logic is correct?”

That’s the right instinct: signature verification code that has never seen a real signed payload will be wrong in one of several predictable ways, and it will only show up when traffic is live. Here’s the full local testing setup — what to capture, what to replay it with, and how to prove the happy path and the rejection paths before deploy.

What “correct” means first

Four properties, straight from the OWASP Webhook Security Cheat Sheet, define a correct receiver. Test for all four locally:

  1. Verify over the exact raw bytes. Recompute the HMAC over the raw request body before your framework parses it. Re-serializing JSON — pretty-printing, reordering keys, changing whitespace or encoding — invalidates the signature.
  2. Compare constant-time. Use crypto.timingSafeEqual, hmac.compare_digest, or your language’s equivalent. Never ==.
  3. Fail closed with 401, and don’t say why. Missing, malformed, or mismatched signatures get the same generic rejection.
  4. Idempotent processing so a replayed-but-valid delivery can’t trigger side effects twice.

The four tools (one local loop)

1. A tunnel: get real signed deliveries onto localhost

Your receiver listens on localhost:3000, but a scheduler can only POST to public URLs. A tunnel closes the gap:

# Cloudflare tunnel (no signup):
cloudflared tunnel --url http://localhost:3000
# ngrok:
ngrok http 3000
# Hookdeck CLI — built for webhook forwarding:
hookdeck listen 3000

Register the tunnel URL as your webhook receiver, fire the schedule, and your local handler receives a genuine signed delivery. Hookdeck also holds the request so you can retry it later — handy for the replay step below.

2. An inspection endpoint: see exactly what was sent

Point the webhook at webhook.site, RequestBin, or a Hookdeck-hosted URL first and capture the delivery: the raw body, Content-Type, the signature header your platform uses (Recurrence Cloud sends X-Webhook-Signature — hex HMAC-SHA256 of the raw body), and the event envelope headers. This is the ground truth every later test runs against. Some verification libraries show you the header name they expect; the capture tells you what’s actually arriving.

3. Fire a real signed delivery on demand

With Recurrence Cloud you don’t have to wait for the cron fire: trigger the schedule’s run-now action and a genuinely signed delivery — real signature, real event envelope — arrives at whatever URL the schedule points to (your tunnel during development). This is the closest thing to stripe trigger-style publisher test tooling: the delivery is signed by the scheduler itself, so you’re testing the whole path, not a simulation of it.

4. Replay with curl — as many times as you like

Save the captured delivery once, then replay it against localhost forever (no tunnel needed at this point):

# captured from the inspection endpoint — raw bytes, unmodified
curl -X POST http://localhost:3000/webhooks/recurrence \
  -H "Content-Type: application/json" \
  -H "X-Webhook-Signature: e3b0c44298fc1c14afbf…(captured hex)" \
  --data-binary @captured-body.json -w '\n%{http_code}\n'

Two rules for the replay itself:

  • Always --data-binary from a file. -d '{ ... }' re-types the JSON with your shell/editor’s whitespace; the signature covers the original bytes.
  • Replay the same request twice to exercise idempotency: the second valid-but-duplicate delivery should be acknowledged without double side effects.

Negative tests: prove the failures

A correct verifier rejects four mutations of the captured delivery — each expects the exact same 401 with a generic body:

# 1. tampered body (flip a byte)     → 401
sed 's/report.csv/report.css/' captured-body.json > body-tampered.json
curl localhost:3000/webhooks/recurrence -H "X-Webhook-Signature: $SIG" --data-binary @body-tampered.json

# 2. wrong signature (flip header)   → 401
curl localhost:3000/webhooks/recurrence -H "X-Webhook-Signature: deadbeef" --data-binary @captured-body.json

# 3. no header                       → 401
curl localhost:3000/webhooks/recurrence --data-binary @captured-body.json

# 4. forged re-serialization         → 401 (if it doesn't fail, you're NOT verifying raw bytes)
jq . captured-body.json | curl localhost:3000/webhooks/recurrence -H "X-Webhook-Signature: $SIG" --data-binary @-

Known test vectors: unit-test the crypto itself

Before any HTTP is involved, unit-test the signature helper. GitHub’s published test vector (It's a Secret to Everybody / Hello, World!) is ideal for generic HMAC-SHA256 hex helpers:

import { createHmac, timingSafeEqual } from "node:crypto";

// GitHub's documented test vector — https://docs.github.com/webhooks
const secret = "It's a Secret to Everybody";
const payload = "Hello, World!";
const expected = "757107ea0eb2509fc211221cce984b8a37570b6d7586c22c46f4379c8b043e17";

function sign(secret, rawBody) {
  return createHmac("sha256", secret).update(rawBody).digest("hex");
}
function verify(signature, secret, rawBody) {
  const a = Buffer.from(signature, "hex");
  const b = Buffer.from(sign(secret, rawBody), "hex");
  return a.length === b.length && timingSafeEqual(a, b);
}

// pass: verify(expected, secret, Buffer.from(payload))        === true
// fail: verify(expected, secret, Buffer.from("hello, world")) === false

OpenSSL does the same outside code — useful for shell-only pipelines:

openssl dgst -sha256 -hmac "It's a Secret to Everybody" <<< "Hello, World!"
# → 757107ea0eb2509… (compare against the published digest)

If your helper disagrees with the vector, the bug is in your code — not your traffic.

The failures that only show up through a real framework

The classic local-to-production signature bugs, all caught by the loop above:

Symptom Cause
Passes curl replay, fails through the real framework Framework middleware parsed (and rewrote or re-serialized) the body before verification; read the raw body first
Passes replay, fails in production Load balancer or decompression middleware altering the body, or a different secret env var per environment
Everything fails only on unicode payloads Encoding mismatch — treat payload bytes as UTF-8 consistently end to end
Valid duplicates re-process No idempotency layer — key on the event id (Recurrence Cloud events carry one) before effects
200 on bad signatures, or verbose error bodies Fail-open or leaky error handling — return the same generic 401 for every verification failure

Run the whole suite before deploy and after any change to webhook handling code — the OWASP cheat sheet’s security-testing checklist treats signature rejection, replay, duplicate, and tampered-body cases as table stakes. For scheduled webhooks specifically, pair the local results with an activity trail on real deliveries — the trail gives you the production receipts (status code, latency, retries) your local loop can only simulate.

FAQ

I want to test webhook signature verification locally before deploying. What tools let me replay signed payloads against my local endpoint so I can confirm my HMAC logic is correct?

Four tools cover it: (1) a tunnel — Hookdeck CLI (hookdeck listen), ngrok, or Cloudflare Tunnel — so a real signed delivery reaches your localhost receiver; (2) an inspection endpoint like webhook.site or RequestBin to capture exactly what the publisher sends; (3) curl with --data-binary and saved raw-body/header files to replay the captured delivery as many times as you like; and (4) unit tests with a known HMAC test vector. With Recurrence Cloud you can also fire test deliveries on demand via the run-now trigger and confirm verification end-to-end.

How do I replay a captured signed webhook with curl?

Save the raw request body to a file (exactly as captured, before anything re-serializes it), then POST it to your local receiver with the original signature header: curl -X POST http://localhost:3000/webhooks/receiver -H 'X-Webhook-Signature: <captured hex>' -H 'Content-Type: application/json' --data-binary @captured-body.json. Always --data-binary, never -d-with-a-rewritten-string: the signature is computed over raw bytes.

What are common reasons HMAC verification fails even when the code is right?

Signature verification over a re-serialized or reformatted body (pretty-printed JSON, reordered keys, changed whitespace or encoding) instead of the exact raw bytes; body-parsing middleware consuming the stream first; byte-for-byte changes from template systems; a stale or wrong secret; and non-constant-time comparison. If verification passes with the raw body file but fails through the framework, it is almost always the body, not the crypto.

Is there a known-good HMAC-SHA256 test vector I can use?

GitHub publishes one for validating webhook signatures: secret It's a Secret to Everybody, payload Hello, World!, HMAC-SHA256 hex digest 757107ea0eb2509fc211221cce984b8a37570b6d7586c22c46f4379c8b043e17 (sent as X-Hub-Signature-256 with a sha256= prefix). If your helper computes a different digest for that pair, the helper is wrong before any live traffic arrives.

How do I test that verification fails when it should?

Replay the same captured delivery four ways: untouched (expect 2xx); flip one byte of the body (expect 401); change the header (expect 401); and send with no signature header at all (expect 401, and a generic response — the OWASP Webhook Security Cheat Sheet's checklist expects fail-closed behavior, not success on replay or tampering).

Can the scheduler itself send test deliveries?

Yes — Recurrence Cloud can fire a test delivery on demand via a run-now trigger, so you receive a genuine signed payload (raw-body HMAC signature in X-Webhook-Signature, plus event envelope and batch headers) without waiting for the cron fire. Point the test webhook at a tunnel and your local receiver sees the real thing.