Security Best Practices

  1. Always verify signatures — Never process webhooks without validating the signature.

  2. Use constant-time comparison — Prevents timing attacks that could leak information about the expected signature.

  3. Check timestamp freshness — Reject webhooks with timestamps older than 5 minutes to prevent replay attacks:

    import time
    
    current_time = int(time.time())
    webhook_time = int(timestamp)
    
    if abs(current_time - webhook_time) > 300:  # 5 minutes
        reject_webhook()
  4. Store your secret securely — Use environment variables or a secrets manager; never commit secrets to version control.

  5. Respond quickly — Return a 2xx response within 30 seconds; process the webhook payload asynchronously if needed.

  6. Use HTTPS — Always use HTTPS for your webhook endpoint to ensure transport-level encryption.

  7. Log failed verifications — Monitor for repeated signature failures which may indicate an attack attempt.


Did this page help you?