debug-a-webhook
Find where a webhook actually stops before touching handler code, including the raw-body signature trap that rejects every valid request.
Save as .claude/skills/debug-a-webhook/SKILL.md in a repository, or under ~/.claude/skills/debug-a-webhook/SKILL.md to have it everywhere. The copy button takes the whole file, frontmatter included.
--- name: debug-a-webhook description: Work out why a webhook is not arriving, not verifying, or arriving twice, in the order that rules out the cheapest causes first. Use when a webhook is missing, failing signature verification, duplicating, or when integrating a new provider's callbacks. --- # Debug a webhook A webhook failure is almost never mysterious. It is one of five things, and they are cheap to tell apart if you check them in the right order. The mistake that costs hours is rewriting handler logic before establishing whether the request ever arrived. ## Establish where it stops, before anything else There are only four possible answers, and you need to know which one you have before forming any theory: 1. The provider never sent it. 2. The provider sent it and it never reached your server. 3. It reached your server and your server rejected it. 4. It reached your handler and the handler failed. Find out which, in this order: - **Check the provider's delivery log first.** Stripe, GitHub, Shopify, Twilio and most others keep one, with the response code they received. This single screen usually ends the investigation. If it shows a 200, the problem is in your handler, not in delivery. - **If the provider shows no attempt**, the event never fired. The subscription is missing, filtered to event types you are not listening for, or pointed at a different environment. Do not debug the receiving end. - **If the provider shows a timeout or a connection error**, you have a network or TLS problem, not an application problem. See below. - **If the provider shows a 4xx or 5xx**, read the body it recorded. Your own error is usually in it. If the provider has no delivery log, point the webhook at a request inspector and fire a test event. Seeing the raw request settles in one minute what guessing settles in an hour. ## The five causes, most common first ### 1. Signature verification on the wrong bytes The most common failure in production, and the most misleading, because the request plainly arrived and your code plainly rejected it. Nearly every provider signs the **raw request body**, byte for byte. If your framework parsed the JSON before your handler saw it, and you re-serialise it to verify, the bytes differ: key order, whitespace, unicode escaping, number formatting. The signature cannot match and never will. The fix is framework-specific but always the same shape: capture the raw body before any body parser runs. In Express this means `express.raw()` on that route only. In Next.js route handlers, read `await request.text()` rather than `await request.json()`. Verify first, parse second. Other signature traps, in order of how often they bite: - Comparing with `==` instead of a constant-time compare. Works, and is a timing vulnerability. - Using the wrong secret: the dashboard shows one per endpoint, and test and live differ. - Forgetting the timestamp. Most schemes sign `timestamp + body`, not the body alone, and reject outside a tolerance window. - Hex versus base64 encoding of the digest. ### 2. The endpoint is not reachable the way the provider reaches it Your browser is not a good test of this. You have DNS cached, a session cookie, and possibly a VPN. The provider has none of those. Check, from outside: - Does the hostname resolve publicly, and to the host you expect. - Is the TLS chain complete. Browsers repair an incomplete chain through AIA fetching and caching; the provider's HTTP client almost certainly does not. This produces the classic "works in my browser, provider reports a TLS error". - Does a plain `POST` to the path return what you expect, with no cookie and no auth header. - Is a WAF, bot protection, or IP allowlist rejecting it. These frequently return a 403 that never reaches application logs, so your logs look empty while the provider sees a rejection. ### 3. Responding too slowly Most providers time out in 5 to 30 seconds and treat a timeout as a failure, then retry. If the handler does the work before responding, a slow downstream call turns into a timeout, a retry, and then duplicate processing. The rule: **acknowledge immediately, process asynchronously.** Verify the signature, write the event to a queue or a table, return 200. Do the work after. A handler that calls three APIs before returning is a handler that will time out eventually. ### 4. Duplicates, because at-least-once is the contract Every major provider retries, and none guarantee exactly-once delivery. A duplicate is not a bug to be prevented, it is a condition to be handled. Use the provider's event ID as an idempotency key. Record processed IDs, and on a repeat, return 200 without reprocessing. Return 200 rather than an error: an error triggers more retries of an event you have already handled. Note that a retried event is not always identical. Some providers resend the current state of the object rather than the state at the time of the event, so ordering assumptions break. Where ordering matters, use the event's own timestamp or version field, not arrival order. ### 5. The handler fails silently A handler that throws after returning 200, or swallows an exception in an async path, shows a clean delivery log and does nothing. Log the event ID at entry and at successful completion, so an event that started and never finished is visible. A delivery log of 200s proves receipt, not processing. ## What to check in what order 1. Provider's delivery log. Response code and body. 2. If no attempt: subscription, event type filter, environment. 3. If timeout or TLS error: resolve the host, check the chain, POST from outside your network. 4. If 4xx: signature verification on raw bytes, then auth, then WAF. 5. If 200 but nothing happened: handler logging, async failure, idempotency table rejecting a first delivery as a duplicate. ## Before you call it fixed - Replay a real event from the provider's dashboard, not a hand-built curl. Hand-built requests have correct signatures only by accident. - Send the same event twice and confirm exactly one effect. - Confirm the handler returns within the provider's timeout under realistic load, not on an idle machine. - State plainly which of the five causes it was. "It works now" after changing several things at once means you do not know, and it will recur. ## Reporting Say which stage was failing and why, and name the evidence: the delivery log entry, the response code, the raw body you compared. If you changed more than one thing, say so, and say which change you believe was the fix and how confident you are.
what it needs
Nothing. This skill is instructions only, so it works in any agent that reads SKILL.md with nothing installed and no account. Save the file and it is live in the next session.
the instructions, in full
Debug a webhook
A webhook failure is almost never mysterious. It is one of five things, and they are cheap to tell apart if you check them in the right order. The mistake that costs hours is rewriting handler logic before establishing whether the request ever arrived.
Establish where it stops, before anything else
There are only four possible answers, and you need to know which one you have before forming any theory:
- The provider never sent it.
- The provider sent it and it never reached your server.
- It reached your server and your server rejected it.
- It reached your handler and the handler failed.
Find out which, in this order:
- Check the provider's delivery log first. Stripe, GitHub, Shopify, Twilio and most others keep one, with the response code they received. This single screen usually ends the investigation. If it shows a 200, the problem is in your handler, not in delivery.
- If the provider shows no attempt, the event never fired. The subscription is missing, filtered to event types you are not listening for, or pointed at a different environment. Do not debug the receiving end.
- If the provider shows a timeout or a connection error, you have a network or TLS problem, not an application problem. See below.
- If the provider shows a 4xx or 5xx, read the body it recorded. Your own error is usually in it.
If the provider has no delivery log, point the webhook at a request inspector and fire a test event. Seeing the raw request settles in one minute what guessing settles in an hour.
The five causes, most common first
1. Signature verification on the wrong bytes
The most common failure in production, and the most misleading, because the request plainly arrived and your code plainly rejected it.
Nearly every provider signs the raw request body, byte for byte. If your framework parsed the JSON before your handler saw it, and you re-serialise it to verify, the bytes differ: key order, whitespace, unicode escaping, number formatting. The signature cannot match and never will.
The fix is framework-specific but always the same shape: capture the raw body
before any body parser runs. In Express this means express.raw() on that route
only. In Next.js route handlers, read await request.text() rather than
await request.json(). Verify first, parse second.
Other signature traps, in order of how often they bite:
- Comparing with
==instead of a constant-time compare. Works, and is a timing vulnerability. - Using the wrong secret: the dashboard shows one per endpoint, and test and live differ.
- Forgetting the timestamp. Most schemes sign
timestamp + body, not the body alone, and reject outside a tolerance window. - Hex versus base64 encoding of the digest.
2. The endpoint is not reachable the way the provider reaches it
Your browser is not a good test of this. You have DNS cached, a session cookie, and possibly a VPN. The provider has none of those.
Check, from outside:
- Does the hostname resolve publicly, and to the host you expect.
- Is the TLS chain complete. Browsers repair an incomplete chain through AIA fetching and caching; the provider's HTTP client almost certainly does not. This produces the classic "works in my browser, provider reports a TLS error".
- Does a plain
POSTto the path return what you expect, with no cookie and no auth header. - Is a WAF, bot protection, or IP allowlist rejecting it. These frequently return a 403 that never reaches application logs, so your logs look empty while the provider sees a rejection.
3. Responding too slowly
Most providers time out in 5 to 30 seconds and treat a timeout as a failure, then retry. If the handler does the work before responding, a slow downstream call turns into a timeout, a retry, and then duplicate processing.
The rule: acknowledge immediately, process asynchronously. Verify the signature, write the event to a queue or a table, return 200. Do the work after. A handler that calls three APIs before returning is a handler that will time out eventually.
4. Duplicates, because at-least-once is the contract
Every major provider retries, and none guarantee exactly-once delivery. A duplicate is not a bug to be prevented, it is a condition to be handled.
Use the provider's event ID as an idempotency key. Record processed IDs, and on a repeat, return 200 without reprocessing. Return 200 rather than an error: an error triggers more retries of an event you have already handled.
Note that a retried event is not always identical. Some providers resend the current state of the object rather than the state at the time of the event, so ordering assumptions break. Where ordering matters, use the event's own timestamp or version field, not arrival order.
5. The handler fails silently
A handler that throws after returning 200, or swallows an exception in an async path, shows a clean delivery log and does nothing. Log the event ID at entry and at successful completion, so an event that started and never finished is visible. A delivery log of 200s proves receipt, not processing.
What to check in what order
- Provider's delivery log. Response code and body.
- If no attempt: subscription, event type filter, environment.
- If timeout or TLS error: resolve the host, check the chain, POST from outside your network.
- If 4xx: signature verification on raw bytes, then auth, then WAF.
- If 200 but nothing happened: handler logging, async failure, idempotency table rejecting a first delivery as a duplicate.
Before you call it fixed
- Replay a real event from the provider's dashboard, not a hand-built curl. Hand-built requests have correct signatures only by accident.
- Send the same event twice and confirm exactly one effect.
- Confirm the handler returns within the provider's timeout under realistic load, not on an idle machine.
- State plainly which of the five causes it was. "It works now" after changing several things at once means you do not know, and it will recur.
Reporting
Say which stage was failing and why, and name the evidence: the delivery log entry, the response code, the raw body you compared. If you changed more than one thing, say so, and say which change you believe was the fix and how confident you are.
check its answers by hand
A skill that reasons well about wrong data is still wrong. For the first few cases, run the same question through a tool that cannot be mistaken.
Get a unique URL, point a webhook at it, and inspect every request it receives in real time.
Open the toolCompute HMAC-SHA256, SHA-1, or SHA-512 signatures from a message and secret key.
Open the toolSend REST requests from your browser, import or copy as cURL, and inspect the status, headers, timing, and response body.
Open the toolFetch a URL from the server, follow redirects, and inspect response and security headers.
Open the toolwhy it is written this way
Webhook integrations fail silently because you cannot see the request. How to capture and inspect real payloads before writing your handler.
How to debug webhooks: see what Stripe, GitHub, and others actually send