Resources / Guides
How to verify Stripe webhook signatures (Node.js and Python)
Verify the Stripe-Signature header correctly in Node.js and Python: raw bodies, the signing secret, timestamps, retries and idempotent handling.
Anyone can send a POST to your webhook URL. Stripe signs every event so you can prove it really came from Stripe — but only if you verify the signature correctly.
How Stripe signs events
Each delivery has a Stripe-Signature header:
Stripe-Signature: t=1700000000,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd
tis the timestamp.v1is an HMAC-SHA256 oft + "." + rawBody, keyed with your endpoint's signing secret (whsec_…, shown in the Stripe dashboard for that endpoint).
Node.js
Use the official library and pass the raw body:
import Stripe from 'stripe';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
export async function handler(req) {
let event;
try {
event = stripe.webhooks.constructEvent(req.rawBody, req.headers['stripe-signature'], process.env.STRIPE_WEBHOOK_SECRET);
} catch (err) {
return { status: 400, body: { error: 'Invalid signature' } };
}
if (event.type === 'checkout.session.completed') {
// fulfil the order
}
return { status: 200, body: { received: true } };
}
Python
import os
import stripe
def handler(req):
try:
event = stripe.Webhook.construct_event(
req["rawBody"], req["headers"].get("stripe-signature"), os.environ["STRIPE_WEBHOOK_SECRET"]
)
except (ValueError, stripe.error.SignatureVerificationError):
return {"status": 400, "body": {"error": "Invalid signature"}}
if event["type"] == "checkout.session.completed":
pass # fulfil the order
return {"status": 200, "body": {"received": True}}
The libraries also reject events whose timestamp is too old (five minutes by default), which blocks replayed requests.
"No signatures found matching the expected signature"
The most common causes:
- The body was parsed and re-serialised. JSON middleware changed whitespace or key order, so the bytes no longer match. Verify against the raw body exactly as received.
- Wrong secret. Each webhook endpoint — and the Stripe CLI — has its own
whsec_…. Test mode and live mode secrets differ too. - The secret has stray whitespace from copy-paste.
- A proxy or framework altered the body (decompression, encoding). Read the raw bytes as early as possible.
Handle retries safely
Stripe retries deliveries that don't get a 2xx response, for up to a few days, and may deliver the same event more than once.
- Answer fast. Acknowledge with 2xx, then do slow work afterwards.
- Deduplicate by
event.id— store processed ids and skip repeats. - Don't rely on order. Fetch the latest state from the API when it matters.
More patterns in webhook receivers done right.
On Wisp
Describe it — "a webhook that verifies Stripe signatures and posts paid invoices to Slack" — and Wisp writes the endpoint with the raw-body verification above, asks for STRIPE_WEBHOOK_SECRET through a private form (it never enters the chat), and gives you the URL to paste into Stripe. Every delivery shows up in the invocation log.
Try it: Template: Stripe webhook to Slack · Template: Stripe Checkout endpoint
Build it with Wisp — describe an API, get it live.