A webhook signature proves that a request really came from the provider and was not changed on the way. Almost every provider uses the same idea: HMAC-SHA256 over the raw request body with a shared secret. The differences are in which header holds the signature, what exactly is signed, and whether the result is hex or Base64.
You can test every example below without writing code: create a URL in the Webhook Tester, send a signed test event, and press Verify signature. To compute an HMAC by hand, use the HMAC generator.
The general algorithm
- Read the raw body bytes exactly as received. Do not parse JSON first.
- Build the signed payload the provider describes (sometimes the body only, sometimes a timestamp plus the body).
- Compute HMAC-SHA256 with your endpoint secret.
- Encode it the way the provider does (hex or Base64).
- Compare with the header value using a constant-time comparison.
- If the provider sends a timestamp, reject events older than a few minutes (replay protection).
Provider cheat sheet
| Provider | Header | Signed payload | Encoding |
|---|---|---|---|
| Stripe | Stripe-Signature: t=…,v1=… | {t}.{raw body} | hex |
| GitHub | X-Hub-Signature-256: sha256=… | raw body | hex |
| Shopify | X-Shopify-Hmac-Sha256 | raw body | Base64 |
| Adyen | additionalData.hmacSignature (in the JSON) | selected fields joined with : | Base64, key is hex-decoded |
| Standard Webhooks (Svix, Resend…) | webhook-signature: v1,… | {webhook-id}.{webhook-timestamp}.{raw body} | Base64, secret is Base64 after whsec_ |
Stripe
The Stripe-Signature header contains a timestamp t and one or more v1 signatures. Sign the string t + "." + rawBody with the endpoint secret (whsec_…, used as-is) and compare the hex result with any v1 value. Stripe's libraries use a 5-minute tolerance for t.
// Node.js (Express): keep the raw body for this route
app.post('/stripe', express.raw({ type: 'application/json' }), (req, res) => {
const header = req.get('Stripe-Signature') || '';
const parts = Object.fromEntries(header.split(',').map(p => p.split('=')));
const signed = `${parts.t}.${req.body.toString('utf8')}`;
const expected = crypto.createHmac('sha256', process.env.STRIPE_WHSEC)
.update(signed).digest('hex');
const ok = header.split(',').filter(p => p.startsWith('v1='))
.some(p => {
const a = Buffer.from(p.slice(3)), b = Buffer.from(expected);
return a.length === b.length && crypto.timingSafeEqual(a, b);
});
const fresh = Math.abs(Date.now() / 1000 - Number(parts.t)) < 300;
res.status(ok && fresh ? 200 : 400).end();
});
In production, prefer stripe.webhooks.constructEvent(); the manual version above is useful for understanding and debugging.
GitHub
# Python (Flask)
import hmac, hashlib
sig = request.headers.get('X-Hub-Signature-256', '')
mac = hmac.new(SECRET.encode(), request.get_data(), hashlib.sha256).hexdigest()
if not hmac.compare_digest(sig, 'sha256=' + mac):
abort(401)
Shopify
Same as GitHub, but the result is Base64 and the secret is your app's client secret:
const digest = crypto.createHmac('sha256', SHOPIFY_SECRET).update(rawBody).digest('base64');
const got = Buffer.from(req.get('X-Shopify-Hmac-Sha256') || '');
const ok = got.length === Buffer.from(digest).length && crypto.timingSafeEqual(got, Buffer.from(digest));
Adyen
Adyen does not sign the whole body. For each NotificationRequestItem it signs these fields joined with colons:
pspReference:originalReference:merchantAccountCode:merchantReference:value:currency:eventCode:success
Empty fields stay empty (two colons in a row). The HMAC key from the Customer Area is a hex string: decode it to bytes first, then Base64-encode the result and compare with additionalData.hmacSignature.
Standard Webhooks (Svix, Resend, Clerk and others)
Sign {webhook-id}.{webhook-timestamp}.{body}. The secret looks like whsec_MfKQ…: strip the prefix and Base64-decode the rest to get the key bytes. The header can hold several space-separated signatures (v1,abc… v1,def…); accept the request if any of them matches.
7 reasons your signature does not match
- You signed parsed JSON, not the raw body.
JSON.stringify(req.body)changes spaces, key order and Unicode escapes. Capture the raw bytes (express.raw,request.get_data(),php://input). - Wrong secret. Test-mode and live-mode endpoints, and every endpoint in the dashboard, have different secrets.
- Hex vs Base64. Stripe and GitHub use hex; Shopify, Adyen and Standard Webhooks use Base64.
- Secret decoding. Adyen's key is hex, Standard Webhooks' key is Base64 after
whsec_; Stripe'swhsec_secret is used as plain text. - Missing prefix. GitHub sends
sha256=, Stripe sendsv1=and Standard Webhooks sendsv1,. - A proxy changed the body. API gateways, WAFs and some frameworks re-encode or decompress bodies. Compare what you received with what the provider shows in its delivery log.
- Clock skew. If your server clock is off by more than the tolerance, valid events are rejected. Use NTP.
Debug it in two minutes
- Open the Webhook Tester and copy your URL.
- Point the provider's test webhook at it (or use Send a signed test event).
- Open the request, press Verify signature, paste the secret. The secret stays in your browser.
- If it verifies there but not in your code, the problem is in how your code reads the body.
FAQ
Is HMAC enough, or do I also need an IP allowlist?
HMAC is the main protection. An IP allowlist is a useful extra layer, but provider IP ranges change, so keep the list up to date.
Why use constant-time comparison?
A normal string comparison stops at the first different character, which can leak information through timing. Use crypto.timingSafeEqual (Node), hmac.compare_digest (Python) or hash_equals (PHP).
Should I return 200 for an invalid signature?
No. Return 400 or 401 and do not process the event. Return 2xx only after the signature is valid and the event is safely stored.