Menu

Stripe signature verification fails in production: the raw body problem
📰

Stripe signature verification fails in production: the raw body problem

DEV Community: express·Hamichi·11 days ago
#ms9a84Ym
#devtoexpress#devto#dev#stripe#const
Long article (2093 words) — no AI summary yet.
Reading 0:00
15s threshold

The webhook verified on your laptop. After deploy, every signature check fails, and the secret in the dashboard is the right one.

Stripe signs the raw request body, not the object you get after JSON.parse . If your framework already parsed JSON, the bytes no longer match the signature. This is the usual way a webhook dies after deploy, because express.json() ran first.

What Stripe actually signs

The Stripe-Signature header is a t= timestamp and one or more v1= hex HMACs of timestamp + "." + rawBody . Stripe's webhook docs describe the scheme, and the official libraries implement it.

You verify that, with a timing-safe compare, before you parse business data. You also reject timestamps older than the usual 300-second window. Without the window, anyone with a captured body can replay it later.

A tolerance of 0 disables the recency check. Stripe's docs say not to use it . The official Node helper, stripe.webhooks.constructEvent , defaults to 300 seconds. Passing 0 to that helper turns the window off.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.