Short answer
Your webhook handler computed a signature over the body it received, with the secret it was given, and it did not match the one Stripe sent. Either the body is not the exact raw text Stripe sent (often because it was parsed as JSON and turned back into a string) or the signing secret is the wrong one (test instead of live, the Stripe CLI’s instead of the dashboard’s). Verify the raw body with the endpoint’s own whsec_ secret. Never skip the verification to make the error go away.
Ask an AI about this page:ChatGPTClaude
On this page
Stripe signs every webhook it sends. It puts a timestamp and an HMAC-SHA256 signature of timestamp.body into the Stripe-Signature header, computed with your endpoint’s signing secret. Your handler repeats that calculation with the body it received and the secret it was given. This message means the two results differ, so the library refused the event. Nothing was processed. Stripe’s own docs put it plainly: at least one of the three inputs, the body, the header or the secret, is wrong. In practice it is almost always the body or the secret.
Find your cause in 30 seconds
| What your handler does | Most likely cause |
|---|---|
await req.json() or express.json() before the check | The body was parsed before the check |
Works with stripe listen, fails live, or the other way round | The signing secret is the wrong one |
| The code reads the raw body, the secret is right, it still fails | Something changed the body on the way |
The error mentions constructEventAsync or a synchronous context | constructEvent instead of constructEventAsync |
We implemented Stripe’s documented v1 signature scheme and ran each cause against it before writing this page. Newer versions of Stripe’s Node library sometimes add a more specific hint to the message: that the body you passed differs from the one Stripe sent (causes 1 and 3), or that your secret’s length or last four characters don’t match (cause 2).
The four causes
1. The body was parsed before the check
The signature covers the exact text Stripe sent: its spacing, its line breaks, the order of its keys. Once you parse it, that text is gone. Turning the object back into a string produces different text, and the signature no longer matches:
import Stripe from "npm:stripe";
const stripe = new Stripe(Deno.env.get("STRIPE_SECRET_KEY")!);
const cryptoProvider = Stripe.createSubtleCryptoProvider();
Deno.serve(async (req) => {
const event = await req.json(); // the raw text is gone after this line
try {
await stripe.webhooks.constructEventAsync(
JSON.stringify(event), // not the bytes Stripe signed
req.headers.get("stripe-signature") ?? "",
Deno.env.get("STRIPE_WEBHOOK_SECRET")!,
undefined,
cryptoProvider,
);
} catch {
return new Response("Invalid signature", { status: 400 });
}
return Response.json({ received: true });
});The same happens in Node apps when app.use(express.json()) runs before the webhook route. Stripe’s docs say to register the webhook route first, or to use a raw body parser for it.
2. The signing secret is the wrong one
Every webhook endpoint has its own signing secret, starting with whsec_. The usual mix-ups:
- Test and live. Test mode and live mode endpoints have different secrets.
- Stripe CLI and dashboard.
stripe listenprints its own secret, which differs from the dashboard endpoint’s. Stripe names a wrong endpoint secret as the most common cause of this error. - Another endpoint. You created a second endpoint, for example after changing the function URL, and kept the old secret.
- Not a webhook secret at all. Your
sk_API key or the publishable key inSTRIPE_WEBHOOK_SECRET. - Extra characters. A space or a line break copied with the secret.
In Supabase, the secret lives in your project’s Edge Function secrets, set in the dashboard or with supabase secrets set.
3. Something changed the body on the way
A proxy, an API gateway or a framework can reformat the body before your code sees it: re-encode it, normalise line breaks or wrap it in another JSON object. Stripe’s docs list frameworks with known problems and how to get the raw body in each. In a Supabase Edge Function, await req.text() gives you the body exactly as Stripe sent it, as long as nothing in front of the function changes it.
4. constructEvent instead of constructEventAsync
Supabase Edge Functions run on Deno, where Stripe’s library verifies with Web Crypto, which only works asynchronously. The synchronous stripe.webhooks.constructEvent then fails with SubtleCryptoProvider cannot be used in a synchronous context. and the hint to use await constructEventAsync(...) instead. It is a different message, but it often shows up while you are fixing this one, and it tempts people to remove the check in the same way.
How to fix it
Read the raw body once with req.text(), verify it with the async API and the endpoint’s secret, and act only on the verified event. This follows the Stripe example in Supabase’s repository:
import Stripe from "npm:stripe";
const stripe = new Stripe(Deno.env.get("STRIPE_SECRET_KEY")!);
// Deno has no synchronous Node crypto: verify with the async API and Web Crypto.
const cryptoProvider = Stripe.createSubtleCryptoProvider();
Deno.serve(async (req) => {
const signature = req.headers.get("stripe-signature") ?? "";
const body = await req.text(); // the raw body, exactly as Stripe sent it
let event: Stripe.Event;
try {
event = await stripe.webhooks.constructEventAsync(
body,
signature,
Deno.env.get("STRIPE_WEBHOOK_SECRET")!, // the whsec_ secret of this endpoint
undefined,
cryptoProvider,
);
} catch (err) {
console.error("Stripe signature check failed:", err instanceof Error ? err.message : err);
return new Response("Invalid signature", { status: 400 });
}
if (event.type === "checkout.session.completed") {
// Fulfil the order here, using only the verified event.
}
return Response.json({ received: true });
});Then make sure the secret matches the endpoint:
- In the Stripe dashboard, open Workbench → Webhooks, pick the endpoint whose URL is your function, and reveal its signing secret. Check that you are in the right mode, test or live.
- Store exactly that value as
STRIPE_WEBHOOK_SECRETin your Supabase Edge Function secrets, without quotes or spaces. - For local testing with
stripe listen, use the secret the CLI prints, and switch back afterwards.
The function runs with verify_jwt = false, because Stripe has no Supabase token. That makes the signature check the only gate, which is why the next box matters. Verified events can still arrive twice, so pair this with idempotent event handling.
My Stripe webhook fails with “No signatures found matching the expected signature for payload”. Find the webhook handler (for example supabase/functions/stripe-webhook/index.ts). Fix it like this: read the raw body once with await req.text() before anything else touches it, never call req.json() or JSON.stringify on the body before verification, and verify with await stripe.webhooks.constructEventAsync(body, the stripe-signature header, Deno.env.get(“STRIPE_WEBHOOK_SECRET”), undefined, Stripe.createSubtleCryptoProvider()). Return 400 when verification throws and do nothing else in that case. Use only the verified event afterwards.
Do not skip, weaken or bypass the verification, do not set the tolerance to 0, and do not log the webhook secret. Then tell me which webhook endpoint and mode (test or live) the STRIPE_WEBHOOK_SECRET has to come from, so I can check the value in the Stripe dashboard myself.
Check that the fix works
Send a signed test event through the Stripe CLI to your deployed function, with the CLI’s secret set as STRIPE_WEBHOOK_SECRET while you test:
stripe listen --forward-to https://YOUR_PROJECT_REF.supabase.co/functions/v1/stripe-webhook
stripe trigger checkout.session.completedstripe listenshows200for the event. The function logs show no signature error.- Send an unsigned request to your own endpoint:
curl -X POST https://YOUR_PROJECT_REF.supabase.co/functions/v1/stripe-webhook -d '{"type":"checkout.session.completed"}'. It must answer400, and nothing may change in your database. - Set the dashboard endpoint’s secret again and check Workbench → Webhooks → your endpoint → Event deliveries after the next real event: it must show as delivered, not failed. The Stripe security guide covers checkout and subscriptions around it.
Frequently asked questions
Can I just skip the signature check until it works?
No. The webhook URL is public, so without the check anyone can send a made-up ‘payment succeeded’ event and get your product for free. The error is the check doing its job on a wrong input. Fix the input: the raw body and the right secret.
Which secret is the right one?
The signing secret of the exact endpoint that sends the event. It starts with whsec_. Test mode and live mode have different ones, every dashboard endpoint has its own, and stripe listen prints yet another one for local testing. It is never your sk_ API key.
It works with stripe listen but fails in production. Why?
Because stripe listen signs with the CLI’s own secret. Your production endpoint in the dashboard has a different whsec_ secret, and the function’s STRIPE_WEBHOOK_SECRET must hold that one. If you test and run live from the same function, use one endpoint and secret per environment.
Why does my function say constructEventAsync instead?
That is a different error: the synchronous constructEvent cannot use Deno’s Web Crypto. Supabase Edge Functions run on Deno, so use await stripe.webhooks.constructEventAsync with Stripe.createSubtleCryptoProvider(), as Supabase’s Stripe example does.
Sources
- 1.Receive Stripe events in your webhook endpoint — Stripe Docs
- 2.Manage webhook endpoints: fix signature verification errors — Stripe Docs
- 3.stripe-node: Webhooks.ts — Stripe on GitHub
- 4.Stripe webhooks example for Edge Functions — Supabase on GitHub
- 5.Function Configuration — Supabase Docs