
Your Stripe webhook keeps returning 400 with "No signatures found matching the expected signature for payload", and paid orders are not being marked as paid. In a Next.js app this is almost always one of four things: the request body was parsed before verification, the wrong whsec_ secret is loaded, the secret has a stray newline, or the endpoint URL redirects. This guide shows how to tell which one you have, the App Router route handler I use (tested on Next.js 16.4.6 with stripe-node 23.1.0), and how to stop it coming back.
Quick answer
Stripe signs the exact raw bytes it sends. In a Next.js App Router route, read the body once with await req.text() and pass that string, the Stripe-Signature header and the signing secret of that exact endpoint to stripe.webhooks.constructEvent(). If verification still fails, compare the secret you load with the one shown for the endpoint in Workbench, trim whitespace, and make sure the endpoint URL does not redirect.
What this means for your business
When webhook verification fails, Stripe still takes the customer's money, but your app never hears about it. Orders stay "pending", subscriptions do not unlock, and customers email support asking why they paid for nothing. Stripe retries a failed event for up to three days, so nothing is lost yet, but every hour of failures adds manual clean-up and refund risk.
The fix itself is usually small: one route file and one environment variable. If your developer has already tried "everything" for more than a few hours, or if orders have been missed for more than a day and need to be replayed safely, that is the point to bring in someone who has done it before.
Why does Stripe webhook signature verification fail?
Stripe computes an HMAC-SHA256 of the timestamp plus the raw request body, using your endpoint's signing secret, and sends it in the Stripe-Signature header as t=...,v1=.... Your server repeats the same calculation. Any change to the bytes, or any difference in the secret, produces a different hash. Stripe's own troubleshooting page says at least one of the three inputs is wrong when you see this error.

| Symptom in your logs | Likely cause | Fix |
|---|---|---|
| No signatures found matching the expected signature | Body parsed or re-serialised, or wrong secret | Use req.text(), check the secret for this endpoint |
Works with stripe listen, fails in production | Using the CLI secret in production | Copy the endpoint secret from Workbench |
| Works locally, fails on the host | Secret pasted with a trailing newline or quotes | .trim() the secret and re-save it |
| Unable to extract timestamp and signatures from header | Header missing or mangled by a proxy | Read stripe-signature from the request headers |
| Timestamp outside the tolerance zone | Server clock off, or a replayed old request | Sync the clock (default tolerance is 300 seconds) |
| Stripe shows 301, 302, 307 or 308 | Endpoint URL redirects (apex to www, http to https, trailing slash) | Register the final URL; Stripe treats redirects as failures |
How do I read the raw body in the Next.js App Router?
In the App Router you do not need the old bodyParser: false config. A route handler receives a standard Web Request, and await req.text() gives you the untouched body. The mistake I see most is calling await req.json() first and then passing JSON.stringify(body) to Stripe. That string is not the same bytes: Stripe sends pretty-printed JSON, and re-stringifying removes the whitespace.
Here is the route I use. It lives at app/api/webhooks/stripe/route.ts:
import Stripe from 'stripe';
import { createHash } from 'node:crypto';
export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
// .trim() removes the newline that copy-pasting into a hosting dashboard often adds
const endpointSecret = (process.env.STRIPE_WEBHOOK_SECRET ?? '').trim();
export async function POST(req: Request) {
const signature = req.headers.get('stripe-signature');
if (!signature) {
return new Response('Missing Stripe-Signature header', { status: 400 });
}
// 1. Read the body exactly once, as raw text. Never req.json() before this.
const rawBody = await req.text();
let event: Stripe.Event;
try {
event = stripe.webhooks.constructEvent(rawBody, signature, endpointSecret);
} catch (err) {
// Debug aid: Stripe may add payload=<suffix of SHA-256 of the body> to the header.
// It is NOT signed, so only use it for logging, never for trust.
const sent = /(?:^|,)payload=([0-9a-f]+)/.exec(signature)?.[1];
const ours = createHash('sha256').update(rawBody, 'utf8').digest('hex');
console.error('Stripe signature check failed', {
message: (err as Error).message,
bodyChanged: sent ? !ours.endsWith(sent) : 'unknown',
secretLast4: endpointSecret.slice(-4), // compare with secret=whsec_****xxxx in the header
});
return new Response('Invalid signature', { status: 400 });
}
// 2. Only now parse and act. Keep it fast; queue slow work.
switch (event.type) {
case 'checkout.session.completed':
// await markOrderPaid(event.data.object.id) -- make this idempotent on event.id
break;
default:
break;
}
return Response.json({ received: true, id: event.id });
}I tested this locally with next build and next start, sending events signed with stripe.webhooks.generateTestHeaderString(). The raw-body route returned 200. A second route that called req.json() and re-stringified returned 400 with exactly the "No signatures found" message, and a request signed with a different secret was rejected too.
If you are still on the Pages Router, the fix is different: export config = { api: { bodyParser: false } } from the API route and read the raw buffer yourself, as Stripe's table of framework fixes shows.
How do I know which secret is wrong?
Stripe's guide says the most common cause is the wrong endpoint secret. There are at least three different whsec_ values in a typical project:
- The secret printed by
stripe listenfor local forwarding. - The secret of your test mode endpoint in Workbench.
- The secret of your live mode endpoint in Workbench.
Each endpoint has its own secret, so a staging and a production endpoint on the same account also differ. Stripe now sometimes appends unsigned debug fields to the header, such as secret=whsec_****PzVt and payload=a25aefc6. That is why my handler logs the last four characters of the loaded secret and whether the SHA-256 of the body still ends with the payload value. If secretLast4 does not match the header, you have loaded the wrong secret. If bodyChanged is true, something altered the body before your code. Stripe is clear that these debug fields must never be used for verification, only for diagnosis.
Step-by-step fix checklist
- Open the endpoint in Workbench and check the recent deliveries tab. Note the status code: 400 means your code rejected it, 3xx means a redirect, 404 or 405 means the URL or method is wrong.
- Confirm the URL Stripe calls is the final URL. If your site redirects
example.comtowww.example.com, register thewwwversion. - Reveal the endpoint's signing secret and compare its last four characters with what your server logs. Re-save the environment variable without quotes or a trailing newline, then redeploy.
- Make sure no middleware, proxy or framework helper reads or rewrites the body before your route.
- Replace any
req.json()plusJSON.stringify()with a singleawait req.text(). - Send a test event with
stripe trigger checkout.session.completed(CLI) or resend a failed event from Workbench, and confirm a 200.
How do I verify the fix worked?
Resend one of the failed events from Workbench and watch for a 200. Then check your database: the order or subscription linked to that event should now be updated. Because Stripe retries failed events for three days, the backlog usually clears on its own once the endpoint returns 2xx. If the outage was longer, Stripe's guide shows how to list undelivered events with delivery_success=false and process them, skipping any event ID you have already handled.
How do I stop it happening again?
- Keep the route body-agnostic: read raw text first, parse after verification, every time.
- Store one secret per environment and name them clearly (
STRIPE_WEBHOOK_SECRET_LIVE,..._TEST). - Make fulfilment idempotent on
event.id, because retries and manual replays will deliver some events twice. - Return 2xx quickly and push slow work (emails, PDFs) to a queue, so timeouts do not look like failures.
- Add an alert on 4xx responses from the webhook route. A broken webhook is silent from the customer's side until they complain.
If you take card payments in Sri Lanka, the same webhook discipline applies to other gateways. My PayPal guide for Sri Lankan freelancers covers the account side, and the Stripe integration guide for mobile apps shows where webhooks fit in a full payment flow. If your Next.js app also needs this month's framework patches, see the Next.js November 2026 security release.
Frequently asked questions
Why does Stripe say no signatures found matching the expected signature for payload?
One of the three inputs to constructEvent is wrong: the body was changed before verification, the signing secret belongs to a different endpoint or the Stripe CLI, or the Stripe-Signature header was not passed through. Read the raw body as text and use the secret of the exact endpoint that received the event.
How do I get the raw body for a Stripe webhook in the Next.js App Router?
Call await req.text() once in the route handler and pass that string to stripe.webhooks.constructEvent. Do not call req.json() first, because re-stringifying the parsed object changes the bytes Stripe signed.
Is the Stripe CLI webhook secret the same as the Dashboard secret?
No. The secret printed by stripe listen only works for CLI-forwarded events. Each Dashboard or Workbench endpoint, in test and live mode, has its own whsec secret.
Why does my Stripe webhook work locally but fail in production?
Usually production loads the CLI or test mode secret, the secret was saved with a trailing newline or quotes, or the production URL redirects to another address. Stripe treats any 3xx redirect as a failed delivery.
What does Timestamp outside the tolerance zone mean?
The signed timestamp is older than the allowed window, which is 300 seconds by default in stripe-node. Check the server clock, and do not replay old requests by hand.
Do I lose payments while my webhook is failing?
The customer is still charged, but your app is not told. Stripe retries failed events for up to three days, and you can list undelivered events through the API to process them once the endpoint is fixed.
Can I skip webhook signature verification?
No. Without verification anyone who finds the URL can post fake payment events and unlock paid features. Only a valid v1 signature proves the request came from Stripe.
Sources
- Manage webhook endpoints: resolve signature verification errors (Stripe Docs)
- Next.js App Router webhook signing example (stripe/stripe-node on GitHub)
- stripe 23.1.0 (npm, 2026-10-29)
- next 16.4.6 (npm, 2026-11-09)
- Webhooks DEFAULT_TOLERANCE (300 seconds) (stripe/stripe-node on GitHub)
Keep reading
- Razorpay Webhook Signature Verification Failed: FixRazorpay webhook signature verification fails when you hash parsed JSON or use the wrong secret. Here is a tested Node.js and Next.js fix.
- Flutter Stripe Integration: PaymentSheet, Webhooks and ConnectIntegrate Stripe in Flutter with flutter_stripe: PaymentSheet, Apple Pay and Google Pay, webhooks that fulfil orders, and Stripe Connect for marketplaces.
- PayPal in Sri Lanka 2026: A Freelancer's Guide to What WorksPayPal in Sri Lanka is live for receiving from abroad via Sampath and ComBank. Here is how to set it up, what it costs, and how it compares.
Comments
Share a question or note about this article.
Loading comments…