What a delivery contains
Each delivery is aPOST with a JSON body. The body’s event.name says which event it
is, and each event’s page in the sidebar shows its payload. Three headers carry what you
need to check it:
Find the secret
For an endpoint created through the API, the secret is thesecret that
creating the endpoint returned, or
that your last rotation returned. The
API cannot return it again. Settings → Webhooks also shows the secret of each endpoint
to an admin.
Check the signature
The open-sourcesvix library checks all three headers for you, in most languages, and
also turns away old messages that someone replays:
- Take the part of the secret after
whsec_and decode it from base64. That is the key. - Join
svix-id,svix-timestampand the raw body with dots:<svix-id>.<svix-timestamp>.<body>. - Compute the HMAC-SHA256 of that text with the key, and encode the result in base64.
- Accept the delivery if the result equals any one of the
v1signatures insvix-signature, compared in constant time. - Turn it away if
svix-timestampis more than a few minutes from your current time.
Answer the delivery
Answer with a2xx status as soon as the signature checks out, and do the real work
afterwards, for example from a queue. Any other status, or no answer, counts as a failed
delivery, and Spott tries again later. A retry has the same svix-id, so check it before
you act twice on the same message.