Blog

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.

9 min read
Karolis Rusenas
On this page

Find the error constructEvent threw in the table, then jump to its fix.

Error from constructEventWhat it meansFix
No signatures found matching the expected signature for payloadA parser changed the body, or the secret is wrongRaw body · Secret
Timestamp outside the tolerance zoneThe signature matched, but its timestamp failed the 5-minute check: clock drift or delayed forwardingTiming
Unable to extract timestamp and signatures from headerThe Stripe-Signature header is missing or mangledHeader

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…
  • t is the Unix time when Stripe signed this delivery.
  • v1 is HMAC-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 listen vs the Dashboard. The Stripe CLI prints its own whsec_ 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 localhost that 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:

  1. You pick Stripe in the input's signature verification settings and paste the endpoint's whsec_ secret.
  2. Every incoming webhook is verified, including the 5-minute check, when it arrives. A forged or stale request gets a 401 and is never stored or forwarded.
  3. With re-sign on delivery on, every delivery attempt gets a new Stripe-Signature with 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-Signature to 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.

  1. Start forwarding and copy the secret it prints:
    stripe login
    stripe listen --forward-to localhost:3000/stripe/webhook
    

    stripe listen prints Ready! Your webhook signing secret is whsec_…. Put that value in STRIPE_WEBHOOK_SECRET and restart your handler.
  2. In a second terminal, send an event. The handler should return 200:
    stripe trigger payment_intent.succeeded
    
  3. Change one character of STRIPE_WEBHOOK_SECRET, restart the handler and trigger again. You should get No signatures found matching the expected signature for payload. Restore the secret and restart.
  4. To see the timestamp error, capture one request from the same stripe listen session with its exact body and Stripe-Signature header, 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 same STRIPE_WEBHOOK_SECRET. Expect Timestamp outside the tolerance zone.

Checklist

  • The handler verifies the raw bytes, with no JSON parser before constructEvent.
  • STRIPE_WEBHOOK_SECRET is 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.

Frequently asked questions

How does Stripe webhook signature verification work?

Stripe sends a Stripe-Signature header such as t=1732790000,v1=5257a8.... The v1 value is an HMAC-SHA256 of the timestamp, a dot and the raw request body, keyed with the endpoint's signing secret (whsec_...). Your server recomputes that HMAC with the same secret, compares it in constant time, and checks that the timestamp is no more than 5 minutes old. Stripe's SDKs do all of this in stripe.webhooks.constructEvent (Node) or stripe.Webhook.construct_event (Python).

Why do I get 'No signatures found matching the expected signature for payload'?

The HMAC your server computed doesn't match Stripe's. Almost always the body was parsed and re-serialized as JSON before verification (express.json(), a framework body parser, or req.json() in Next.js), or you used the wrong secret: the Stripe CLI's stripe listen secret instead of the Dashboard endpoint's, a test-mode secret in live mode, or the secret of a different endpoint. Pass the raw request bytes and the secret of the endpoint that sent the event.

Where do I find the Stripe webhook signing secret?

In the Stripe Dashboard, open Workbench, go to the Webhooks tab, select the endpoint and click 'Click to reveal' next to the signing secret, which starts with whsec_. Each endpoint, and test and live mode, has its own secret. When forwarding with the Stripe CLI, stripe listen prints a different secret: 'Ready! Your webhook signing secret is whsec_...'.

What does 'Timestamp outside the tolerance zone' mean?

The signature is valid but its timestamp is more than 5 minutes (300 seconds) away from your server's clock. Either your server's clock is wrong, or the request was delivered late by something between Stripe and your server, such as a proxy retry, a queue, a replay of a captured request, or an agent that was offline. Stripe's own retries are signed fresh each time, so they don't cause it.

Should I increase the Stripe webhook tolerance?

Avoid it. The tolerance argument to constructEvent can be raised, but it widens the window in which a captured webhook can be replayed against you. Fix clock drift with NTP, and if a gateway or queue delivers webhooks late, have it re-sign them with a fresh timestamp instead.

Can a webhook proxy re-sign Stripe webhooks?

Yes, if it knows the endpoint's signing secret. Webhook Relay verifies the Stripe-Signature when the webhook arrives and, with re-sign on delivery turned on, signs every delivery attempt again with the same secret and the current time. Your server keeps calling constructEvent with its existing secret and default tolerance, and retries, replays and late agent deliveries pass.