Signature validation
Rewrite signs every webhook delivery before it reaches your endpoint. You should verify the signature before parsing the JSON body or running any business logic.Signed headers
Every signed delivery includes these headers:svix-idUnique delivery id for the webhook attempt.svix-timestampTimestamp used when the request was signed.svix-signatureSignature header used for verification.
What Rewrite signs
The signature is computed from this exact string:payloadmust be the exact raw request body.- Do not
JSON.parse(...)before verification. - Do not re-stringify the payload before verification.
- Do not trim whitespace or change encoding.
Which secret to use
Use the webhook signing secret returned by:POST /webhooksGET /webhooks/{id}
whsec_....
Verification flow
- Read the raw request body as a string.
- Read
svix-id,svix-timestamp, andsvix-signature. - Decode the webhook secret into key bytes.
- Compute an HMAC-SHA256 over
${svix-id}.${svix-timestamp}.${payload}. - Base64-encode the digest.
- Compare the received signature and the computed signature with a constant-time check.
- Only after that should you parse the JSON and process the event.
Verification function examples
The functions below are framework-agnostic. Pass the raw body string and the originalsvix-* header values exactly as they arrived.
The Node tab follows the same verification pattern used by the Rewrite Node library.
Recommended hardening
Reject stale timestamps when you need tighter replay resistance
Reject stale timestamps when you need tighter replay resistance
Signature verification proves integrity, but you can also enforce your own acceptable timestamp window using
svix-timestamp when your threat model requires stricter replay controls.Store processed delivery ids
Store processed delivery ids
Persist
svix-id or the webhook event id and ignore duplicates safely. Delivery is at-least-once and retries can happen.Keep the endpoint focused on verification and enqueueing
Keep the endpoint focused on verification and enqueueing
Return a
2xx quickly after verification and move slow work into background jobs, queues, or workers.Log failed verification attempts carefully
Log failed verification attempts carefully
Log enough context to debug invalid requests, but avoid logging secrets or raw sensitive payloads in unsafe places.
Common mistakes
- Using
express.json()or another parsed body before verification. - Verifying against the API key instead of the webhook secret.
- Re-stringifying parsed JSON before computing the signature.
- Dropping or renaming the
svix-*headers in proxies or middleware. - Using a normal string comparison instead of a constant-time comparison.