Overview
All Daya webhooks include anX-Daya-Signature header containing an HMAC-SHA256 signature of the payload. Always verify this signature to ensure the webhook came from Daya.
Signature Header
Verification Algorithm
- Get raw request body as string
- Compute HMAC-SHA256 using your webhook secret
- Compare computed signature with
X-Daya-Signatureheader - Use timing-safe comparison to prevent timing attacks
Implementation Examples
Important Notes
Use raw request body
Use raw request body
Critical: Compute HMAC on the raw request body before parsing JSON. Parsing changes whitespace and ordering, breaking the signature.
Use timing-safe comparison
Use timing-safe comparison
Regular string comparison (==) is vulnerable to timing attacks. Use constant-time comparison:
- Node.js:
crypto.timingSafeEqual() - Python:
hmac.compare_digest() - Go:
hmac.Equal() - PHP:
hash_equals()
Keep secrets secure
Keep secrets secure
- Store webhook secret in environment variables
- Never commit secrets to version control
- Rotate secrets regularly
- Use different secrets for sandbox and production
Testing Verification
Generate test signatures for local testing:Common Issues
Signature always fails
Signature always fails
Possible causes:
- Using wrong webhook secret
- Not using raw request body
- Character encoding issues
Intermittent failures
Intermittent failures
Cause: Parsing JSON before verificationFix: Always compute HMAC on raw body, then parse JSON