How Webhook Signatures Work
Exa uses HMAC SHA256 to sign webhook payloads. The signature is included in theExa-Signature
header, which contains:
- A timestamp (
t=
) indicating when the webhook was sent - One or more signatures (
v1=
) computed using the timestamp and payload
Verification Process
To verify a webhook signature:- Extract the timestamp and signatures from the
Exa-Signature
header - Create the signed payload by concatenating the timestamp, a period, and the raw request body
- Compute the expected signature using HMAC SHA256 with your webhook secret
- Compare your computed signature with the provided signatures
python
Security Best Practices
Following these practices will help ensure your webhook implementation is secure and robust:- Always Verify Signatures - Never process webhook data without first verifying the signature. This prevents attackers from sending fake webhooks to your endpoint.
-
Use Timing-Safe Comparison - When comparing signatures, use functions like
hmac.compare_digest()
in Python orcrypto.timingSafeEqual()
in Node.js to prevent timing attacks. - Check Timestamp Freshness - Consider rejecting webhooks with timestamps that are too old (e.g., older than 5 minutes) to prevent replay attacks.
- Store Secrets Securely - Store your webhook secrets in environment variables or a secure secret management system. Never hardcode them in your application. Important: The webhook secret is only returned when you create a webhook - make sure to save it securely as it cannot be retrieved later.
- Use HTTPS - Always use HTTPS endpoints for your webhooks to ensure the data is encrypted in transit.
Troubleshooting
Invalid Signature Errors
If you’re getting signature verification failures:- Check the raw payload: Make sure you’re using the raw request body, not a parsed JSON object
- Verify the secret: Ensure you’re using the correct webhook secret from when the webhook was created
- Check header parsing: Make sure you’re correctly extracting the timestamp and signatures from the header
- Encoding issues: Ensure consistent UTF-8 encoding throughout the verification process
Testing Signatures Locally
You can test your signature verification logic using the webhook secret and a sample payload:python
What’s Next?
- Learn about webhook events and their payloads
- Set up webhook retries and monitoring
- Explore webhook management endpoints