Stripe signature verification fails in production: the raw body problem
Updated 22 Nov 2026. The 3 a.m. version of this bug is almost always express.json() running first.
Stripe signs the raw request body, not the object you get after JSON.parse.
The Stripe-Signature header is a t= timestamp and one or more
v1= hex HMACs of timestamp + "." + rawBody. Several
v1 values appear while you roll a secret. You verify that, with a timing-safe
compare, before you parse business data. You also reject timestamps outside the usual
300-second window, or anyone with a captured body can replay it later. A tolerance of 0
disables the window; don't use it.
If your framework already parsed JSON, the bytes no longer match the signature. The check fails every time, in production, with a secret that is otherwise correct. This is the most common way a "it worked on my machine" webhook dies after deploy.
Express: raw on the route, JSON after it
Mount express.raw({ type: "application/json" }) on the webhook route, and
register that route before any global app.use(express.json()).
import express from "express";
const app = express();
// stripeWebhookRoute lives in the kit's examples/express.ts
app.post(
"/webhooks/stripe",
express.raw({ type: "application/json" }),
stripeWebhookRoute(deps),
);
app.use(express.json()); // everything else
The route should refuse a body that is not a Uint8Array. If
express.json() already ran, log that and return 500 so you find it, rather than
verifying a reserialized object that will never match.
if (!(req.body instanceof Uint8Array)) {
log("stripe webhook: body is not raw. Is express.json() running first?", {});
res.status(500).json({ error: "raw_body_missing" });
return;
} Next.js and NestJS
In Next.js App Router, read await req.text() (or arrayBuffer()) and
pass those exact bytes to the verifier. Do not req.json() first.
In NestJS, create the app with { rawBody: true } and disable JSON parsing
for the webhook route only.
The other practical trap is verifying a test secret against live events, or the other way around. That also fails the signature. It is a different bug, and it looks identical in the logs until you print which secret you used (not the value, the name).
The Hamichi Webhook Kit takes the raw body and the signature header, and will not parse business data until the check passes. Once the body is trusted, you still have to process a retry once: Why Stripe sends your webhook twice. The rest of the production list is in Stripe webhooks: the production gotchas.