The key is your secret’s base64 part, after
whsec_.
With a library
200, and do the work afterwards. Once you answer 2xx, Postinger counts the delivery as done and won’t send it again, so an event you only held in memory is lost if handling it fails. If storing it fails, answer 5xx and Postinger retries.
By hand
1
Rebuild what was signed
Join the
webhook-id header, the webhook-timestamp header and the raw request body with dots: {id}.{timestamp}.{body}. Use the body exactly as it arrived, before any JSON parsing.2
Sign it
Base64-decode the part of your secret after
whsec_, and compute the HMAC-SHA256 of the string with it. Base64-encode the result.3
Compare
webhook-signature holds one or more space-separated v1,<signature> entries. Accept the request if any of them matches yours, compared in constant time.4
Check the time
Reject requests whose
webhook-timestamp is more than a few minutes from your clock, so an old request can’t be replayed.Rotating the secret
Rotate the secret under Webhooks if it may have leaked. The old secret keeps signing alongside the new one for 24 hours, sowebhook-signature carries both while you switch over.