Signature check
HMAC-SHA256 over the timestamp and the raw body, with a five-minute tolerance.
Every delivery carries Hevia-Signature: t=<unix seconds>,v1=<hex> where
Text
v1 = HMAC-SHA256(secret, "<t>.<raw body>")and secret is the whsec_… value shown once when the subscription was created.
- Read the raw bytes of the body. Re-serialised JSON has different bytes and never matches.
- Parse
tandv1from the header. - Reject the request when
tis more than 300 seconds away from now (replays). - Compute the HMAC and compare it in constant time.
import { constructEvent, WebhookSignatureError } from "@hevia/sdk";
// rawBody: the request body exactly as received (string or Buffer)
try {
const event = constructEvent(rawBody, req.headers["hevia-signature"], process.env.HEVIA_WEBHOOK_SECRET!);
if (event.livemode && event.type === "deal.won") await queue.add(event);
} catch (err) {
if (err instanceof WebhookSignatureError) return res.status(400).end();
throw err;
}Tip
A full receiver with Express is in the guide Receive and verify a webhook.