Stripe webhook error: no signatures found matching the expected signature

Why Stripe webhook signature checks fail with no signatures found matching the expected signature for payload, and how to fix the secret and the raw body.

Simon, Founder of Shipyard

By · Founder of Shipyard

3 minute read

What the error means

Stripe signs every webhook it sends. Your code recomputes that signature from the request and a secret, and compares the two. The message No signatures found matching the expected signature for payload means the two did not match. Stripe's own troubleshooting names the two usual causes: the wrong signing secret, or a request body that was changed before your code checked it.

Nothing is wrong with Stripe when you see this, and retrying will not help: Stripe will keep retrying the event, and every attempt will fail the same way until the secret or the body is fixed. Your dashboard shows the failed deliveries, which is useful for testing the fix.

Cause one: the wrong secret

Stripe says the most common cause is using the wrong endpoint secret. Every webhook endpoint has its own signing secret, which starts with whsec_. It is not your API key, and it is different for every endpoint you create. Test mode and live mode have separate endpoints, so they have separate secrets too.

The usual ways to end up with the wrong one are predictable. You went live and kept the test secret. You deleted and recreated the endpoint, which gives it a new secret. You have two endpoints pointing at the same address and copied the other one's secret. Or you are testing locally with the Stripe CLI, which forwards events with its own secret, different from the one in the dashboard.

Fix it by opening the endpoint in the Stripe dashboard, revealing its signing secret, and comparing it character for character with the value your server actually reads, usually STRIPE_WEBHOOK_SECRET. Stripe's guide suggests printing the secret your code uses during debugging, then removing that log line afterwards.

Cause two: the body was changed

The signature covers the exact bytes Stripe sent. Stripe's documentation says the body must be the string Stripe sent, in UTF-8, without any changes. If a framework parses the JSON first and you then turn it back into a string, the spacing and order can differ, and the check fails even with the right secret.

In Express, a global JSON parser is the classic culprit. Give the webhook route a raw body parser of its own. In a Next.js route handler, read the body with await req.text() and pass that string to Stripe, never the result of req.json(). Proxies can also alter the body or its encoding, which is why some apps pass locally and fail only once deployed behind one.

TypeScript
// 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() // the raw string, not req.json()
  const signature = req.headers.get('stripe-signature') ?? ''
  let event: Stripe.Event
  try {
    event = stripe.webhooks.constructEvent(body, signature, process.env.STRIPE_WEBHOOK_SECRET!)
  } catch {
    return new Response('Bad signature', { status: 400 })
  }
  // Record event.id and skip events you have already handled, then act on it.
  return new Response(null, { status: 200 })
}

A quick order of checks

  1. Open the endpoint in the dashboard and confirm its address is the route you are debugging.
  2. Copy that endpoint's signing secret and compare it with the value on your host, in the same mode, test or live.
  3. Redeploy or restart after changing the variable, since many hosts only read environment variables at start.
  4. Make sure the route passes the raw request text to the verification call, with no JSON parsing in between.
  5. Resend a failed event from the dashboard and watch for a 200.

Do not switch the check off

It is tempting to skip verification to make the error go away. Do not. The webhook address is public, and the signature is the only thing that proves an event really came from Stripe and not from someone pretending a payment succeeded. Fix the secret or the body instead. Once it passes, also record each event's ID so a retried event is never handled twice; the companion article on webhooks covers that part.

What Shipyard does here

A launch creates the webhook endpoint on your real domain in test mode, writes its signing secret to your host as STRIPE_WEBHOOK_SECRET next to the matching API key, and sends a test event as part of the health check, so a mismatch shows up before your first customer. Moving to live mode replaces the keys and the secret together, which avoids the most common version of this error.

Sources

Launch in an hour, not a weekend

Shipyard connects your accounts once, then sets up the domain, hosting, database, email and payments for every new product.

Get started See how it works

Read next