Webhook signature verification thumbnail: seven receiver mistakes that accept forged or replayed events

Webhook Signature Verification: 7 Mistakes We Reproduced

We wrote seven webhook receivers, each with one small mistake, for the three signature schemes most startups end up handling: Stripe’s, GitHub’s, and Standard Webhooks (the one OpenAI uses). Then we attacked them. All seven accepted events they shouldn’t have.

The surprise is where the failures are. Webhook signature verification itself, the HMAC part, is the easy bit, and the official libraries get it right. Three of our attacks still worked against the official libraries, because the libraries did exactly what they promise and our handler did the rest wrong.

Here are the requests, the fixes, and a grep you can run on your own code today.

Key takeaways

  • 7 mistakes tried, 7 reproduced, 7 closed by the fix. Three of them needed nothing but the endpoint URL.
  • The official Stripe, Standard Webhooks and GitHub libraries stop missing headers, blank secrets and old timestamps. None of them stops a duplicate delivery, a wrong-tenant event or a stale GitHub push. That’s your handler’s job.
  • With stripe-node defaults, the same genuine event was accepted 21 times in a row and granted 21,000 credits instead of 1,000. A unique constraint on event.id fixed it.

The lab: three signature schemes, one app, seven receivers

We built one Express 5.3.0 app on Node v22.23.4 and ran it on 127.0.0.1 only. We pinned stripe 23.1.0, standardwebhooks 1.1.1 and @octokit/webhooks-methods 6.0.0. Our scripts played the sender, using test secrets and the documented formats. We didn’t use real Stripe, GitHub or OpenAI accounts.

The three formats, as documented:

  • Stripe: Stripe-Signature: t=...,v1=, an HMAC-SHA256 of t.rawBody (Stripe docs).
  • Standard Webhooks: webhook-id, webhook-timestamp and webhook-signature, signed over msg_id.timestamp.payload (spec). OpenAI’s webhooks follow it.
  • GitHub: X-Hub-Signature-256: sha256=, the HMAC hex digest of the request body (GitHub docs).

What an attacker wants in our app: invoice.paid grants 1,000 credits to the account named in the event, member.removed removes a user from a workspace, and a GitHub push to main deploys the after sha. We pinned everything with --save-exact --ignore-scripts and skipped a standardwebhooks release that was under 24 hours old, the same habits as our npm supply chain checklist.

ID Mistake Who can exploit it What happened After the fix
W1 Verify only if (sig) Anyone with the URL Unsigned invoice.paid: 200, credits 0 to 1000 400, credits 0
W2 Env var typo plus || '' Anyone with the URL Event signed with an empty key: 200, 1000 credits 400, credits 0
W3 Timestamp ignored Anyone holding one old delivery 3-day-old delivery replayed 10 times: 10/10 accepted, 10,000 credits 400, credits 0
W4 Official library, no duplicate check Anyone holding a delivery under 5 minutes old 1 legit + 20/20 replays in 0.02 s: 21,000 credits 20/20 flagged duplicate, 1,000 credits
W5 Error returns the expected signature Anyone with the URL Two requests, no secret: 200, 1000 credits Generic 400
W6 Tenant taken from the body An admin of another tenant Globex-signed event removed al***@**me.test from Acme 403, Acme unchanged
W7 GitHub dedupe on X-GitHub-Delivery only Anyone holding one old delivery Live sha rolled back from f00dbab to a1b2c3d {"ignored":"stale push"}

Three needed only the URL (W1, W2, W5). Three needed one captured delivery (W3, W4, W7). One needed a legitimate account on another tenant (W6). The captured-delivery attacks have a real precondition: you need a copy of a genuine delivery, from a request bin, logs that keep bodies and headers, or a shared tunnel. TLS protects them in transit. We didn’t model how an attacker gets one.

W1 and W2: no header, no secret, no problem for the attacker

W1 is the classic fail-open. The handler checks the signature only when there is one:

POST /hooks/w1/stripe HTTP/1.1
Host: 127.0.0.1:5302
content-type: application/json

{"id":"evt_10aad78be196b477","type":"invoice.paid","data":{"object":{"id":"in_58d908ba9764","amount_paid":4900,"metadata":{"account":"globex"}}}}

HTTP/1.1 200
{"route":"w1","account":"globex","credits_now":1000}

No Stripe-Signature header, so no check, so 1,000 credits. A control request with a wrong signature got a 400, which is why this bug survives testing. The “bad signature” case works. The “no signature” case is the one nobody tries.

This isn’t just a lab toy. CVE-2026-72861 (the appwrite templates github-issue-bot) describes the same shape: when the X-Hub-Signature-256 header is absent, the check “reports success without performing any HMAC verification”. NVD lists it under CWE-347 with a status of Deferred. It’s an advisory for a code flaw, and we’re not claiming anyone was hit.

W2 is quieter. The code reads process.env.STRIPE_SIGNING_SECRET || '', but the deploy sets STRIPE_WEBHOOK_SECRET. Nothing crashes. The app just signs with an empty key, and the startup banner told us so if we’d been reading it: W2 secret length=0. We computed HMAC-SHA256(key='', t + '.' + body) ourselves:

POST /hooks/w2/stripe HTTP/1.1
content-type: application/json
stripe-signature: t=1794977994,v1=bbcd6a055dea...

{"id":"evt_e5d89daba529d33d","type":"invoice.paid", ...}

HTTP/1.1 200
{"route":"w2","account":"globex","credits_now":1000}

The same class shows up in the wild. According to the GitHub advisory for CVE-2026-86080, n8n’s GitHub Trigger accepted deliveries “without a stored secret”. It’s fixed in 1.123.76, 2.37.7 and 2.38.2.

One note on Stripe’s docs. The Ruby snapshot-event sample on the webhooks page wraps verification in if endpoint_secret. In the sample, endpoint_secret is a hardcoded placeholder, so it’s fine as written. But if you port that pattern to an env var and the variable is unset, verification quietly turns off.

Both W1 and W2 are closed by default in the official libraries. stripe-node, standardwebhooks and octokit all rejected a missing header and a blank secret in our matrix. Our fix was to refuse to boot without the secret and always call the library. OWASP ASVS 5.0 requirement 16.5.3 (L2) is about exactly this: preventing fail-open conditions such as processing a transaction despite errors in validation logic. It’s the same family as the alg mistakes in our JWT post: the crypto is fine, the checks around it aren’t. And it’s a pattern we see in generated glue code, too, as in our vibe-coding pentest.

W5: the error message that signed the request for us

This one is our favourite. The receiver had a debug mode that told the caller why verification failed. Request 1, with a junk signature:

POST /hooks/w5/stripe HTTP/1.1
content-type: application/json
stripe-signature: t=1794977994,v1=000000000000...

{"id":"evt_18e38a69d9b0db6c","type":"invoice.paid", ...}

HTTP/1.1 400
{"error":"signature mismatch","why":"no matching v1","expected":"02409394960a..."}

It handed us the signature it expected. Request 2, same body and same t, with that value:

POST /hooks/w5/stripe HTTP/1.1
content-type: application/json
stripe-signature: t=1794977994,v1=02409394960a...

{"id":"evt_18e38a69d9b0db6c","type":"invoice.paid", ...}

HTTP/1.1 200
{"route":"w5","account":"globex","credits_now":1000}

Two requests, no secret. We read stripe-node’s source for this one: its error messages never include the expected HMAC, so this is a hand-rolled-code problem. The fix is a generic 400 ({"error":"invalid signature"}) and server-side logs that don’t contain the computed value either. MITRE tracks this as CWE-209.

W3 and W4: webhook replay attacks and what “5 minute tolerance” means

In W3 the handler checked the signature and ignored the timestamp. We took a genuine delivery from three days earlier (t=1794718794) and sent it ten times. All ten were accepted, and the account ended with 10,000 credits. With the default 300 second tolerance, the same delivery got a 400.

Stripe’s docs say the libraries default to a 5-minute tolerance, and “Don’t use a tolerance value of 0“, because it disables the recency check entirely. Our library matrix agrees: stripe-node with tolerance 0 accepted the 3-day-old delivery.

W4 is the one that should worry people who did everything right. The route used stripe-node 23.1.0 constructEvent(rawBody, header, secret) with defaults, and nothing else. We sent one legit delivery and then the identical request 20 more times within 0.02 seconds:

HTTP/1.1 200
{"route":"w4","account":"globex","credits_now":1000}      # legit

HTTP/1.1 200
{"route":"w4","account":"globex","credits_now":21000}     # replay #20

All 20 replays were accepted: 21,000 credits instead of 1,000. That’s a lab counter, not a revenue figure. And it isn’t a library bug. The signature is valid and the timestamp is fresh, so the library has no reason to refuse.

The providers all tell you to handle this yourself. Stripe: “Webhook endpoints might occasionally receive the same event more than once”, so log the event IDs you’ve processed. The Standard Webhooks spec says to use webhook-id as an idempotency key. OpenAI says it “may deliver duplicate copies” and says to dedupe on webhook-id. Retries make duplicates happen anyway: Stripe retries for up to three days in live mode, OpenAI for up to 72 hours.

Our fix keys on the signed event.id. Because the id sits inside the signed body, a replayer can’t change it. With it, the first delivery got 1,000 credits and replay #20 got:

HTTP/1.1 200
{"duplicate":"evt_b9389788c40d2a31"}

20 of 20 flagged, 0 extra grants, 1,000 credits.

W6: a valid signature from the wrong tenant

W6 needs no forged signature at all. We modelled per-workspace inbound webhooks, Standard Webhooks signed. The secret is picked from the URL (/hooks/w6/ws/globex), but the action is applied to data.workspace_id from the body. A Globex admin legitimately holds the Globex secret. First, the control, sending a Globex-signed event to Acme’s endpoint:

POST /hooks/w6/ws/acme HTTP/1.1
webhook-id: msg_db8a63b5681d6afe
webhook-timestamp: 1794977994
webhook-signature: v1,e2YkfhXL3M...

{"type":"member.removed","data":{"workspace_id":"acme","email":"al***@**me.test"}}

HTTP/1.1 400
{"error":"invalid signature"}

Good, the signature is checked against Acme’s key. Now the same event, same signature, to Globex’s own endpoint:

POST /hooks/w6/ws/globex HTTP/1.1
webhook-id: msg_db8a63b5681d6afe
webhook-timestamp: 1794977994
webhook-signature: v1,e2YkfhXL3M...

{"type":"member.removed","data":{"workspace_id":"acme","email":"al***@**me.test"}}

HTTP/1.1 200
{"workspace":"acme","removed":"al***@**me.test","removed_count":1,"members_now":["ca***@**me.test"]}

The signature was fine. The binding was the bug. The endpoint verified Globex’s key and then did what the body said about Acme. MITRE calls this CWE-639, authorization bypass through a user-controlled key. Svix makes the sender-side version of this point in its post on signature failure modes: bind signatures to a per-consumer value.

The fix is a rule: the tenant is whoever’s key verified. If the body names a tenant, it has to match, or you return 403. Ours did, with Acme’s members untouched:

HTTP/1.1 403
{"error":"event workspace does not match endpoint"}

It’s the same rule behind Postgres row-level security: never trust tenant context the caller controls.

W7: GitHub signs the body, not the delivery ID

GitHub’s docs say X-Hub-Signature-256 “is the HMAC hex digest of the request body”. They describe X-GitHub-Delivery as “a globally unique identifier (GUID) to identify the event”. Its best-practices page suggests using the delivery header “to ensure that each delivery is unique per event” as replay protection.

That works against an identical resend. It doesn’t work against someone who changes the header, because the header isn’t covered by the HMAC. In our lab we deployed push a1b2c3d, merged a fix, deployed push f00dbab, then resent the captured a1b2c3d push. With its original delivery id, dedupe caught it:

x-github-delivery: faa230c9-2b75-40bc-9f4e-7518ca34b2c9
x-hub-signature-256: sha256=e99bc353700e...

HTTP/1.1 200
{"duplicate":"faa230c9-2b75-40bc-9f4e-7518ca34b2c9"}

Same body, same signature, new GUID:

x-github-delivery: 947f2c1b-32c3-4f31-9204-e258bb3a63e4
x-hub-signature-256: sha256=e99bc353700e...

HTTP/1.1 200
{"deployed":"a1b2c3d","previous":"f00dbab"}

The live build went back to the old commit, with the fix rolled out of production. octokit’s verify accepted the 3-day-old delivery and 20 of 20 repeats too, which is by design: GitHub’s scheme has no timestamp. To be precise, we aren’t saying GitHub’s advice is wrong. Deduping on the delivery id stops accidental duplicates, not a deliberate replayer.

Our fix treats the push as a hint. Before deploying, fetch the branch head from the API and act only if after matches it:

HTTP/1.1 200
{"ignored":"stale push","push_after":"a1b2c3d","current_head":"f00dbab"}

Stripe’s thin events work on the same idea: fetch the related object instead of trusting the payload.

Webhook signature verification in the official libraries: what they stop, and what they can’t

We called each library directly with the same hostile inputs.

Input stripe 23.1.0 standardwebhooks 1.1.1 @octokit/webhooks-methods 6.0.0
No signature header reject reject reject
Blank secret reject reject reject
Genuine delivery, 3 days old reject reject accept (no timestamp in the scheme)
Same, tolerance 0 accept n/a n/a
Same genuine delivery 20x inside 5 min accept 20/20 accept 20/20 accept 20/20
Genuine delivery, id header changed n/a reject (id is signed) n/a (X-GitHub-Delivery is unsigned)
Body parsed to an object first reject (needs string or Buffer) n/a n/a

Read it like this. The libraries close W1, W2, W3 and W5 by default. None of them closes W4, W6 or W7, because those happen after verification passes. That’s the whole post in one table, and it’s why “we use the official SDK” isn’t a complete answer.

One more thing we saw, which we didn’t count as a mistake. A verifier that HMACs JSON.stringify(req.body) instead of the raw bytes rejected 5 of 6 genuinely signed payload shapes (pretty-printed, trailing newline, é, \/ and 1.0). Only compact ASCII passed. That’s not a forgery bug, but it’s what pushes teams to switch verification off. Stripe and OpenAI both say to use the raw body, so put express.raw() on that route and add a test that posts a pretty-printed signed payload.

For comparison, stripe-node compares signatures with crypto.timingSafeEqual after a length check. We read that in the source and did not test timing attacks.

Check your own receivers in one grep

This is the script we ran on the lab. It’s seven patterns, read-only, and every hit needs a human look.

d="${1:-.}"
g() { echo "## $1"; grep -rnE --include='*.js' --include='*.ts' --include='*.mjs' --include='*.py' --include='*.rb' --include='*.go' --exclude-dir=node_modules --exclude-dir=.git "$2" "$d" | grep -v '^\s*//' ; echo; }
g "A1 verification wrapped in if(header) or if(secret)" "if \(\s*!?\s*(sig|signature|sigHeader|endpoint_?[sS]ecret|webhook_?[sS]ecret)[A-Za-z_]*\s*\)"
g "A2 webhook secret with an empty-string fallback" "(SECRET|secret)[A-Za-z_]*['\"]?\]?\s*(\|\||\?\?|or)\s*['\"]{2}"
g "A3 tolerance 0 or timestamp check disabled" "(constructEvent|construct_event|ConstructEvent)\([^)]*,\s*0\s*\)|checkTimestamp:\s*false|tolerance\s*[:=]\s*0\b"
g "A4 expected/computed signature returned or logged" "(expected|computed)[A-Za-z_]*\s*[:,)].*(res\.|json|send|log|print)|(res\.|json|send|log|print).*\b(expected|computed)[A-Za-z_]*"
g "A5 HMAC over re-serialized JSON" "JSON\.stringify\((req|request)\.body\)|json\.dumps\(request\.(json|get_json)|(update|hmac|HMAC)\([^)]*(JSON\.stringify|json\.dumps|to_json)"
g "A6 plain == / === on a signature" "(sig|signature|digest)[A-Za-z_]*\s*(===|==|!==|!=)\s*[A-Za-z_]"
g "A7 dedupe keyed on X-GitHub-Delivery only" "x-github-delivery|X-GitHub-Delivery|HTTP_X_GITHUB_DELIVERY"

On the lab it flagged W1, W2, W3, W5, W7 and the re-serialized body, so 5 of 7 mistakes. It found nothing for W4 or W6, because a missing check has no line to grep. It produced no hits on the fixed routes. Be honest about what that means: we wrote the patterns knowing our own bugs, so this is a starting point and not a scanner. W4 and W6 need someone to read the handler, plus a two-tenant test.

The fixed route

This is the fixed Stripe route from the lab, minus app plumbing. It’s illustrative, and the comments carry the points.

const secret = process.env.STRIPE_WEBHOOK_SECRET;
if (!secret) throw new Error('STRIPE_WEBHOOK_SECRET missing: refusing to start'); // no '' fallback

app.post('/webhooks/stripe', express.raw({ type: 'application/json' }), async (req, res) => {
  let event;
  try {
    // raw Buffer, default 300 s tolerance; never pass 0
    event = stripe.webhooks.constructEvent(req.body, req.get('stripe-signature'), secret);
  } catch {
    return res.status(400).json({ error: 'invalid signature' }); // nothing about what was expected
  }
  // event.id is inside the signed body, so it can't be changed by a replayer
  const fresh = await db.query(
    'INSERT INTO processed_events (id) VALUES ($1) ON CONFLICT DO NOTHING RETURNING id', [event.id]);
  if (fresh.rowCount === 0) return res.json({ duplicate: event.id });
  await handle(event); // tenant comes from your own mapping of the verified account, not a free-form body field
  res.json({ ok: true });
});

In production, do the dedupe insert in the same transaction as the side effect, and keep ids longer than the provider’s retry window (three days for Stripe, 72 hours for OpenAI). For GitHub, add one line before acting on a push: compare payload.after with the branch head from GET /repos/{owner}/{repo}/branches/{branch} and skip if they differ.

The fix list, in order

  1. Use the provider’s library on the raw body. It closes W1, W2, W3 and W5 by default. The catch is that body parsers have to be bypassed on that route, which is easy to break in a refactor.
  2. Fail closed at boot. No secret, no start. No || '', no if (secret). Add it to your deploy checks, because a missing env var now takes the service down. That’s the point.
  3. Dedupe on a signed id (Stripe event.id, Standard Webhooks and OpenAI webhook-id) with a unique constraint. The table grows, so prune it past the retry window.
  4. Keep the default tolerance, never 0, and sync your clocks. A skewed clock rejects genuine events, so watch your 400 rate.
  5. Bind the tenant to the key and return 403 on mismatch. It’s more plumbing than one global endpoint.
  6. For high-impact actions like deploys, treat the webhook as a hint and re-fetch state from the provider API. Queue the calls so rate limits don’t bite.
  7. Return generic errors and keep logs quiet. Never return or log the computed signature.
  8. Put five tests in CI: an unsigned request, a blank-secret request, an old timestamp, the same event twice, and a cross-tenant event. All five should fail.

If you also send webhooks to customer-supplied URLs, that’s a different problem, covered in our SSRF post. And if your product is an AI agent or integration that receives GitHub or OpenAI events, the same “verify every inbound call” rule applies to the tools it exposes, as we cover in our MCP OAuth post.

What we didn’t test

This was one app, Node only. We didn’t test the Python, Ruby or Go SDKs, or any framework’s built-in webhook helper. We didn’t test timing attacks, secret brute-forcing or IP allowlisting. We built the vulnerable receivers on purpose, so these are mechanisms, not measurements of how common each mistake is.

FAQ

Is verifying the webhook signature enough?

No. The signature proves who sent the bytes. It doesn’t stop a replay inside the tolerance window, a duplicate delivery, or a handler that acts on the wrong tenant. In our lab the official Stripe library accepted the same event 21 times.

How do I stop webhook replay attacks?

Check the signed timestamp against a short tolerance, which the official libraries do by default, and record the event or message id from the signed content so each one is processed once. For GitHub, which signs only the body, also re-check state against the API before acting.

Can I use X-GitHub-Delivery to prevent replays?

It catches an identical resend, which covers accidental duplicates. The header isn’t covered by the HMAC, so someone holding an old delivery can swap in a new one. In our lab that redeployed an old commit and rolled back a fix.

Should I return a helpful error when a signature fails?

Return a generic 400 and log the details server-side, without the computed value. Our debug error returned the expected signature to the caller, so a forged event got through on the second request with no secret at all. Keep detail in your own logs only.

Your library verifies the signature. Who verifies the rest of the handler?

Webhook handlers sit on billing, deploys and access control, and they’re easy to leave out of a pentest scope. Our web and API pentests cover them, including the two-tenant tests that no grep can do. If an enterprise buyer or auditor is asking, our SOC 2 pentest guide explains what they look for. Or start with a free external snapshot, no access needed.

Last updated 18 November 2026. Tested 18 November 2026 by the NoMoreBreach Team, on our own local lab only. Signatures are shortened and test secrets are not shown. Library versions: stripe 23.1.0, standardwebhooks 1.1.1, @octokit/webhooks-methods 6.0.0.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *