Skip to main content
Always verify webhook signatures to ensure requests come from Kapso.

Signature verification

Kapso signs all webhooks with HMAC SHA256 using your webhook secret key. The signature is included in the X-Webhook-Signature header.

How it works

  1. Kapso creates a signature by hashing the raw JSON payload with your secret key
  2. The signature is sent in the X-Webhook-Signature header
  3. Your endpoint recreates the signature using the same method
  4. 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 the X-Idempotency-Key header to track processed events.

Simple in-memory tracking

Database-backed tracking

Best practices

  1. Verify signatures first - Before processing any webhook data
  2. Return 200 quickly - Respond within 10 seconds to avoid retries
  3. Process asynchronously - Use background jobs for heavy processing
  4. Handle duplicates - Implement idempotency using X-Idempotency-Key
  5. Monitor failures - Set up alerts for signature verification failures
  6. Use HTTPS only - Never accept webhooks over HTTP
  7. Rotate secrets - Change webhook secrets periodically
  8. Log everything - Keep audit logs of webhook deliveries and failures