hooksig / Stripe
HMAC-SHA256 · hex · timestamped
Stripe
The one everyone hits first, and the one whose 'signature verification failed' error is the most Googled.
Try it — live, in your browser
Request — edit anything
Verify this in code
import { verify } from "hooksig";
const result = await verify("stripe", {
payload: rawBody, // the RAW body, not parsed JSON
headers: request.headers,
secret: env.WEBHOOK_SECRET,
});
if (!result.verified) {
return new Response(result.reason, { status: 400 });
}no match — signature invalid
Signed string
HMAC-SHA256( secret, signed string ) = expected
Expected vs provided
expected
provided
How it's built
The scheme
- Header
Stripe-Signature - AlgorithmHMAC-SHA256
- Encodinghex
- Timestampyes, so it has replay protection
- SignsHMAC-SHA256 over `{timestamp}.{rawBody}`, hex-encoded. The whsec_ endpoint secret is used verbatim as the key.
Gotchas
- Sign the RAW body. Re-stringified JSON changes bytes and every check fails.
- The signed payload is `{t}.{body}`, not just the body.
- The header can carry several v1 values during secret rotation. Any match is valid.
- Reject if `t` is outside your tolerance (default 5 minutes) to stop replays.