How do I verify a webhook signature?
Recalculate the signature with your signing secret and compare it with the one in the X-Webhook-Signature header. Process the event only if they match.
- Take the X-Webhook-Timestamp header, a full stop and the raw request body, exactly as received.
- Calculate an HMAC of that text with your signing secret, using the algorithm in the webhooks guide.
- Compare your result with the value in X-Webhook-Signature using a constant-time comparison.
- Reject the request if the timestamp is too far from your server's time.
Use the raw body: if you parse and re-serialise the JSON first, the signature won't match. Details and code samples are in the webhooks guide.