Webhook Testing and Debugging: A Practical Guide
Webhooks invert the usual testing model: instead of your client calling an API, someone else's server calls yours, on its own schedule, with payloads you don't control. That makes them harder to test than a normal endpoint — you can't just click "send" and watch the response. Here's a practical approach to capturing, verifying and replaying webhook traffic without guessing.
1. Give yourself a stable place to receive them
Before you can debug a webhook, you need to see it land. Three common setups, in order of how often you'll use them:
- A public capture endpoint — a disposable HTTPS URL that logs every request it receives, useful for a first look at a provider's payload shape and headers during integration.
- A tunnel to your local machine (e.g. a reverse proxy tool) — exposes
localhostso the real provider can deliver to code you're actively debugging in a terminal or IDE. - A logging middleware in staging — the most representative option, since it runs the real handler but writes the raw request body and headers to a log or table before processing, so nothing is lost even if the handler throws.
Whichever you use, capture the raw body, not a parsed object. Signature verification and some payload quirks (field order, numeric precision) only show up in the raw bytes.
2. Treat every webhook delivery as an untrusted HTTP request
A webhook is just an inbound POST — test it the same way you'd test any endpoint that accepts untrusted input, plus a signature check:
- Missing or malformed signature header → must be rejected with
401, never silently accepted. - Valid signature, unexpected payload shape → should fail gracefully (log +
400), not crash the handler. - Duplicate delivery → the same event ID arriving twice (providers retry on any non-2xx, including timeouts) must not create two records. See the point on idempotency below.
- Out-of-order delivery → an older event arriving after a newer one for the same resource. If your handler assumes strict ordering, add a timestamp or version check.
3. Verify signatures correctly — most bugs live here
Most providers sign webhooks with an HMAC over the raw body plus a shared secret, and send the signature in a header. The most common real-world bugs are:
- Verifying against the parsed and re-serialized JSON instead of the exact raw bytes received — re-serialization can reorder keys or change number formatting, breaking the signature even when the payload is legitimate.
- Using a non-constant-time string comparison for the computed vs. received signature, which leaks timing information.
- Forgetting to also bind a timestamp header into the check, which allows an old, otherwise-valid payload to be replayed by an attacker who captured it.
// Node.js example: verify, don't just decode
const crypto = require('crypto');
function isValid(rawBody, signatureHeader, secret) {
const expected = crypto.createHmac('sha256', secret)
.update(rawBody) // raw bytes, not JSON.stringify(parsed)
.digest('hex');
return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(signatureHeader));
}
When you're building the sending side of a webhook integration, use RestRuno to hand-craft a signed request against your own endpoint: set the raw body, compute the HMAC in a pre-request script, and send it as a normal POST. This lets you test your receiver against known-good and deliberately-tampered payloads without waiting for a real provider event.
4. Replay captured payloads instead of waiting for new events
Once you've captured a real payload (headers included), save it as a fixture and replay it on demand — against local, staging or production-like environments — rather than triggering the source event again. This turns an intermittent, hard-to-reproduce bug into a one-click repro:
- Store the exact headers (including the signature) and raw body together; a signature computed against a different secret per environment won't replay cleanly, so keep per-environment fixtures or recompute the signature at replay time.
- Keep a small library of fixtures per event type (created, updated, failed, refunded…) so a new handler can be exercised against every shape before it ever sees live traffic.
- Replay the same fixture twice in a row as a quick idempotency regression test.
5. Design for retries, not just the first delivery
Providers retry failed deliveries — often with exponential backoff over many hours. Your handler must be safe to run more than once for the same event:
- Store the provider's event ID and check it before processing; skip (but still return
200) if already seen. - Return
2xxas soon as the event is durably queued, and do slow work (emails, downstream calls) asynchronously — a handler that times out looks identical to a provider as a failure and triggers a retry, doubling the work. - Log every delivery attempt with its event ID and outcome, so a burst of retries is diagnosable instead of mysterious.
Quick checklist
- ✔ Raw body + headers captured and logged, not just the parsed object
- ✔ Missing/invalid signature → 401, never processed
- ✔ Signature verified against raw bytes with a constant-time comparison
- ✔ Duplicate event IDs are no-ops, not duplicate side effects
- ✔ Handler returns 2xx fast; slow work happens after, asynchronously
- ✔ A fixture library of real payloads, replayable per event type
- ✔ Out-of-order and malformed payloads fail gracefully, not with a 500
Craft and replay signed webhook requests
RestRuno is a free, local-first REST client with scripting and environments — build an HMAC-signed request by hand, save it as a fixture, and replay it against local, staging or production whenever you need to reproduce a webhook bug.
Download RestRuno — free