Verifying a webhook signature
Build the string t.body from the X-CalcLib-Signature header, compute HMAC-SHA256 with your secret, and compare before you act on the delivery.
A webhook endpoint added in Webhooks receives a signed POST each time someone runs your embed. Every delivery carries an X-CalcLib-Signature header of the form t=<unix time>,v1=<signature>.
Verify before you parse
- Read the raw request body. Parsing and re-serialising the JSON changes the bytes, and the signature will never match.
- Take
tfrom the header and build the stringt.body: the timestamp, a dot, then the raw body. - Compute HMAC-SHA256 of that string with your endpoint secret, as hex.
- Compare it with each
v1value in constant time. While you rotate a secret, the header can carry twov1values; either may match. - Reject the delivery if
tis more than 5 minutes from your clock.
Deliveries that fail
They are retried after 1 minute, 5 minutes, 30 minutes, 2 hours and 8 hours. An endpoint that fails 20 times in a row is disabled and we email you, following the product switch in Notifications.