Verify Stripe webhook signatures: t= and v1=
Stripe sends Stripe-Signature: t=<seconds>,v1=<hex>, the HMAC-SHA256 of t + '.' + raw body.
Header structure
Stripe-Signature is a comma-separated list of key=value pairs. t is the signing time in Unix seconds; v1 is the HMAC-SHA256 hex. During a secret rollover there can be more than one v1, and other versions may appear alongside.
t=1764300783,v1=5f2c8b0d9a4e7c1f3b6d8e0a2c4f6b8d0e2a4c6f8b0d2e4a6c8f0b2d4e6a8c0f
The signed payload is t + "." + raw body. Drop the dot, or use the current time instead of the header's t, and it can never match.
Node.js verification
app.post("/webhooks/stripe", express.raw({ type: "*/*" }), (req, res) => {
const raw = req.body;
const header = req.get("Stripe-Signature") || "";
let t = "", v1 = [];
for (const part of header.split(",")) {
const i = part.indexOf("=");
if (i < 0) continue;
const k = part.slice(0, i), v = part.slice(i + 1);
if (k === "t") t = v;
else if (k === "v1") v1.push(v);
}
const expected = crypto.createHmac("sha256", SECRET)
.update(Buffer.concat([Buffer.from(t + "."), raw]))
.digest("hex");
const ok = v1.some(v =>
v.length === expected.length &&
crypto.timingSafeEqual(Buffer.from(v), Buffer.from(expected)));
const fresh = Math.abs(Math.floor(Date.now() / 1000) - Number(t)) <= 300;
if (!ok || !fresh) return res.status(401).send("invalid");
res.status(200).send("ok");
});The timestamp window
Stripe recommends a default tolerance of 300 seconds. If the difference between the request time and now exceeds it, reject the request even when the signature matches. Without this check a captured request can be replayed indefinitely.
| Situation | Verdict |
|---|---|
| v1 matches, |t − now| ≤ 300 | accept |
| v1 matches, t older than 300 s | reject (possible replay) |
| v1 matches, t more than 300 s ahead | reject (skew or forgery) |
| v1 does not match | reject (tampering or wrong secret) |
A server clock that is minutes off rejects every valid request. Keep NTP running, and raise the window only slightly if you must.
Common mistakes
- Passing a parsed object to
constructEventinstead of the raw string or buffer. - Reading only the first v1 and failing when several are present.
- Ignoring t and recomputing with the current time.
- Mixing test-mode and live-mode whsec values.
Compute t and v1 separately and see the request age at the same time.
Open the signature verifierFrequently asked questions
How do I test locally with the Stripe CLI?
Run stripe listen --forward-to localhost:3000/webhooks/stripe and use the whsec_… it prints for that session. The value can change when the session restarts.
Should v0 signatures be verified too?
Only v1 (SHA-256) is needed today. v0 is deprecated and can be ignored if present.
What if events arrive out of order?
Stripe does not guarantee order. Compare event.created and the object state, ignore stale events, and make processing idempotent.
This guide follows the signing schemes published by GitHub, Stripe, Slack, Shopify and Toss Payments.
← Guides