Signature verification
Kapso signs all webhooks with HMAC SHA256 using your webhook secret key. The signature is included in theX-Webhook-Signature header.
How it works
- Kapso creates a signature by hashing the raw JSON payload with your secret key
- The signature is sent in the
X-Webhook-Signatureheader - Your endpoint recreates the signature using the same method
- Compare signatures using a timing-safe comparison
Node.js example
Python example
Ruby example
Important notes
Use the raw payload
Always verify against the raw JSON payload, not a parsed object:Use timing-safe comparison
Never use=== or == to compare signatures. Use timing-safe comparison to prevent timing attacks:
Store secrets securely
- Never hardcode webhook secrets in your code
- Use environment variables or secret management services
- Rotate secrets periodically
- Use different secrets for development and production
Idempotency
Webhooks may be delivered more than once. Use theX-Idempotency-Key header to track processed events.
Simple in-memory tracking
Database-backed tracking
Best practices
- Verify signatures first - Before processing any webhook data
- Return 200 quickly - Respond within 10 seconds to avoid retries
- Process asynchronously - Use background jobs for heavy processing
- Handle duplicates - Implement idempotency using
X-Idempotency-Key - Monitor failures - Set up alerts for signature verification failures
- Use HTTPS only - Never accept webhooks over HTTP
- Rotate secrets - Change webhook secrets periodically
- Log everything - Keep audit logs of webhook deliveries and failures

