Stripe Webhook Signature Verification: Fix the Three Common Errors
Signature mismatch? Check the raw request body and the endpoint's whsec_ secret. Timestamp error? Check clock drift and delayed forwarding. Header error? Make sure Stripe-Signature reaches your handler intact.
On this page
Find the error constructEvent threw in the table, then jump to its fix.
Error from constructEvent | What it means | Fix |
|---|---|---|
No signatures found matching the expected signature for payload | A parser changed the body, or the secret is wrong | Raw body · Secret |
Timestamp outside the tolerance zone | The signature matched, but its timestamp failed the 5-minute check: clock drift or delayed forwarding | Timing |
Unable to extract timestamp and signatures from header | The Stripe-Signature header is missing or mangled | Header |
Stripe signs every delivery attempt fresh, including its own retries, so the timestamp error almost always points at something between Stripe and your server. Python's version of that error also appends the timestamp.
How Stripe signs a webhook
Every Stripe webhook carries a Stripe-Signature header:
Stripe-Signature: t=1732790000,v1=5257a869e7ecebeda32aff…
tis the Unix time when Stripe signed this delivery.v1isHMAC-SHA256(secret, t + "." + rawBody), in hex.- The secret is the endpoint's signing secret, which starts with
whsec_. The whole string, prefix included, is the key.
To verify, your server recomputes the HMAC over the raw body, compares it in constant time, and rejects the request if t is more than 300 seconds from its own clock. That check is what stops an attacker who captured one real webhook from replaying it later. Stripe's SDKs do all of it in one call: stripe.webhooks.constructEvent in Node, stripe.Webhook.construct_event in Python.
When you roll the secret, Stripe can keep the old one active for up to 7 days and sends one v1 value per active secret. A match on any of them is valid.
Fix 1: verify the raw body
The HMAC is computed over the exact bytes Stripe sent. If a body parser turns them into an object and your code serializes it back, whitespace and key order change and the signature no longer matches. This is the most common cause of No signatures found matching the expected signature for payload.
Express. Mount express.raw() on the webhook route, and register the route before any global express.json():
const express = require('express')
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY)
const app = express()
app.post('/stripe/webhook', express.raw({ type: 'application/json' }), (req, res) => {
let event
try {
event = stripe.webhooks.constructEvent(
req.body, // a Buffer, not an object
req.headers['stripe-signature'],
process.env.STRIPE_WEBHOOK_SECRET
)
} catch (err) {
return res.status(400).send(`Webhook Error: ${err.message}`)
}
// handle event.type ...
res.json({ received: true })
})
app.use(express.json()) // everything else
Next.js (App Router). Read the body with req.text(), never req.json():
// app/api/stripe/webhook/route.ts
import Stripe from 'stripe'
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!)
export async function POST(req: Request) {
const body = await req.text()
const sig = req.headers.get('stripe-signature')!
let event: Stripe.Event
try {
event = stripe.webhooks.constructEvent(
body,
sig,
process.env.STRIPE_WEBHOOK_SECRET!
)
} catch (err) {
return new Response(`Webhook Error: ${(err as Error).message}`, { status: 400 })
}
// handle event.type ...
return Response.json({ received: true })
}
FastAPI. Take the bytes from await request.body(), not a Pydantic model:
import os, stripe
from fastapi import FastAPI, Request, HTTPException
app = FastAPI()
@app.post("/stripe/webhook")
async def stripe_webhook(request: Request):
payload = await request.body()
sig = request.headers.get("stripe-signature")
try:
event = stripe.Webhook.construct_event(
payload,
sig,
os.environ["STRIPE_WEBHOOK_SECRET"],
)
except (ValueError, stripe.SignatureVerificationError) as e:
# older stripe-python versions: stripe.error.SignatureVerificationError
raise HTTPException(status_code=400, detail=str(e))
# handle event["type"] ...
return {"received": True}
Flask is the same idea with request.get_data(). Anything that sits in front of your app, such as an API gateway mapping template, a serverless body transform or a middleware that decompresses and re-encodes, can also change the bytes. Log the raw body's length and a hash on both sides if you're unsure.
Fix 2: use the right whsec_ secret
Where to find it: in the Stripe Dashboard, open Workbench → Webhooks, select the endpoint and click Click to reveal next to the signing secret. When you forward events with the Stripe CLI, stripe listen prints its own secret instead: Ready! Your webhook signing secret is whsec_….
Every endpoint has its own signing secret, and the wrong one produces exactly the same error as a parsed body:
stripe listenvs the Dashboard. The Stripe CLI prints its ownwhsec_when it starts forwarding. It's not the secret of the endpoint you created in the Dashboard.- Test mode vs live mode. The same URL registered in both modes has two different secrets.
- Several endpoints. If two endpoints point to the same URL, each event is signed with the secret of the endpoint that sent it.
- Copy-paste damage. A trailing newline in an environment variable is enough to break the match.
You can check a secret without touching your code. Paste the payload, the Stripe-Signature header and the secret into the free Stripe webhook signature verifier, which runs in your browser.
Fix 3: "Timestamp outside the tolerance zone"
The signature matched, but its timestamp failed the freshness check: t is more than 300 seconds from your server's clock. Check your server clock first, then whether something held or replayed the original request. Clock drift: run NTP. Late delivery: re-sign, don't raise the tolerance.
Clock drift. If your server's clock is minutes off, every webhook fails. Run NTP (chronyd, systemd-timesyncd) and check with date -u.
Late delivery. Stripe signs each delivery attempt when it sends it. In Stripe's words, it generates "a new signature and timestamp for the new delivery attempt". Its automatic retries (up to three days in live mode) and the Resend button in the Dashboard therefore carry a fresh timestamp. The problem starts when something between Stripe and your server stores the request and delivers the original later:
- a webhook proxy or gateway that retries a failed delivery after your server comes back
- replaying captured webhooks from logs after fixing a bug
- a queue or rate limiter that holds requests during a burst
- a tunnel or agent to
localhostthat was disconnected while your laptop slept, then delivers the backlog - CI or test fixtures that reuse recorded webhooks
Each of those delivers an authentic webhook whose signature is now 10 minutes, an hour or a day old, and constructEvent correctly refuses it.
The fix: re-sign the delivery
The fix is to give each late delivery a fresh signature. That's only safe in the system that can verify the original first, and that holds the same secret. Webhook Relay does this on the input:
- You pick Stripe in the input's signature verification settings and paste the endpoint's
whsec_secret. - Every incoming webhook is verified, including the 5-minute check, when it arrives. A forged or stale request gets a
401and is never stored or forwarded. - With re-sign on delivery on, every delivery attempt gets a new
Stripe-Signaturewith the current time, made with the same secret over the body actually sent.
Your server's code doesn't change. It calls constructEvent with the same secret and the default tolerance. A delivery that was retried after an outage, replayed from the logs, or queued for an agent on localhost passes like a webhook sent a second ago. Only webhooks that passed verification on arrival are re-signed, so re-signing can't launder a forged request.
The same applies to the other providers that sign a timestamp: Svix-based senders such as Clerk and Resend, and Slack. Why webhook signatures fail after retries and replays covers those.
Don't raise the tolerance instead
constructEvent takes a fourth argument, the tolerance in seconds, and Python has tolerance=. It's tempting to set it to a day. That makes every webhook you ever received replayable against your endpoint for a day, which is the attack the timestamp exists to stop. Turning verification off for "internal" traffic has the same problem.
Fix 4: pass the Stripe-Signature header through
Unable to extract timestamp and signatures from header means the SDK got no Stripe-Signature value, or one without t= and v1=. Check three things:
- You read the right header. In Node it's
req.headers['stripe-signature'], lowercase. In Next.js and FastAPI,headers.get('stripe-signature'). - Nothing in front of your app drops it. Some API gateways, load balancers and serverless proxies forward only an allowlist of headers. Add
Stripe-Signatureto it. - Nothing rewrites it. A proxy that folds or truncates long header values breaks the
t=…,v1=…format.
Test it with the Stripe CLI
Verify a fresh event first, then reproduce a mismatch and a timestamp failure.
- Start forwarding and copy the secret it prints:
stripe login stripe listen --forward-to localhost:3000/stripe/webhookstripe listenprintsReady! Your webhook signing secret is whsec_…. Put that value inSTRIPE_WEBHOOK_SECRETand restart your handler. - In a second terminal, send an event. The handler should return
200:stripe trigger payment_intent.succeeded - Change one character of
STRIPE_WEBHOOK_SECRET, restart the handler and trigger again. You should getNo signatures found matching the expected signature for payload. Restore the secret and restart. - To see the timestamp error, capture one request from the same
stripe listensession with its exact body andStripe-Signatureheader, for example in a free Webhook Bin. Check that it verifies while fresh. More than five minutes later, send the same body and header to your handler with the sameSTRIPE_WEBHOOK_SECRET. ExpectTimestamp outside the tolerance zone.
Checklist
- The handler verifies the raw bytes, with no JSON parser before
constructEvent. -
STRIPE_WEBHOOK_SECRETis the secret of this endpoint, in this mode, with no whitespace. - The server clock is synced by NTP.
- Nothing between Stripe and the server strips or rewrites
Stripe-Signature. - Anything that can deliver late (a gateway, a queue, replays, a tunnel) re-signs, or is the thing that verifies.
- The tolerance is the default 300 seconds.
- Handlers are idempotent on
event.id, because retries and replays deliver the same event again.
For HMAC in general, see how to verify a webhook signature. For the delivery side, see reliable webhook delivery.
