Validate Deliveries

This guide explains how to validate Clearout webhook deliveries using HMAC signature verification. Validating webhook requests properly guarantees their authenticity and prevents your application from receiving malicious requests.

Why Validate Webhooks

Webhook validation is crucial for security and includes protection against:

  • Replay Attacks - Timestamps prevent old requests from being replayed

  • Request Tampering - HMAC signatures ensure data integrity

  • Unauthorized Requests - Only requests with valid signatures are processed

  • Data Spoofing - Verification confirms requests originate from Clearout

Important

Always validate webhook signatures in production. Never process webhook data without proper verification, as this could lead to security vulnerabilities and data corruption.

Signature Format

Clearout sends webhook signatures in the x-co-webhook-signature header with the following format:

t=,v1=

Signature Components

  • t - Unix timestamp (UTC) when the webhook was created

  • v1 - HMAC-SHA256 signature of the payload

How Signatures Are Generated

Clearout generates signatures using the following process:

  • Create a string by concatenating the timestamp and raw JSON payload: timestamp.payload

  • Generate HMAC-SHA256 hash using your webhook secret token

  • Encode the hash as a hexadecimal string

  • Include both timestamp and signature in the header

General Instructions for Any Language

When implementing webhook verification in any programming language, follow these core steps:

1

Parse Signature Header

Extract the timestamp and signature from the x-co-webhook-signature header:

2

Construct Data String

Create the data string for HMAC calculation using this exact format:

Critical: Use Raw Body

Always use the raw request body as received, before any parsing or modifications:

  • Before JSON parsing - Use the raw string before converting to JSON objects

  • Before any processing - Don't modify, trim, or reformat the body

  • Exact match required - The body must match exactly what was sent by Clearout

  • Preserve formatting - Maintain original whitespace, indentation, and field ordering

3

Calculate HMAC

Generate HMAC SHA256 signature using your webhook secret:

4

Verify Signature

Compare signatures using constant-time comparison to prevent timing attacks:

5

Validate Timestamp (Optional)

Check that the timestamp is recent to prevent replay attacks (optional but recommended):

Recommended Time Window

We recommend validating timestamps within a 2-minute window, but you can choose any grace period between 2-5 minutes based on your security requirements and system performance needs. This validation is optional but helps prevent replay attacks.

6

Return Response

Always return HTTP 200 status for successful webhook processing:

Important: HTTP Status Codes

Your webhook endpoint must return HTTP 200 for successful processing. Any other status code will cause Clearout to retry the webhook delivery according to the retry schedule.

JavaScript Example

Key Features

  • Signature Verification - Validates HMAC-SHA256 signature

  • Timestamp Validation - Prevents replay attacks (2-minute window)

  • Error Handling - Proper error responses for different failure scenarios

  • Security - Uses environment variables for secrets

  • Logging - Detailed console output for debugging

Python Example

Important Notes for Python

  • Raw Body - Use request.get_data(as_text=True) to get the exact raw body string

  • JSON Stringify - The raw body must match exactly what was sent, including whitespace and formatting

  • HMAC Compare - Use hmac.compare_digest() for secure signature comparison

  • Error Handling - Always wrap signature verification in try-catch blocks

  • Environment Variables - Store your webhook secret in environment variables for security

PHP Example

Important Notes for PHP

  • Error Handling - Always validate signature header exists before processing

  • Timestamp Validation - Validates timestamps within 2 minutes (recommended range: 2-5 minutes)

  • Hash Equals - Use hash_equals() for secure signature comparison

  • Environment Variables - Store your webhook secret in environment variables for security

Security Best Practices

Secret Management

  • Store securely - Never hardcode secrets in your application code

  • Use environment variables - Store secrets in environment variables or secure key management systems

  • Rotate regularly - Update your webhook secret periodically for enhanced security

  • Access control - Limit access to webhook secrets to authorized personnel only

Validation Requirements

  • Always validate - Never skip signature validation, even in development

  • Check timestamps - Reject requests older than 5 minutes to prevent replay attacks

  • Use constant-time comparison - Use secure comparison functions to prevent timing attacks

  • Return appropriate status codes - Return HTTP 200 for successful processing

Timestamp Validation (Optional)

Verify that the webhook timestamp is recent to prevent replay attacks:

  • Extract timestamp from the signature header

  • Calculate age by comparing with current time

  • Reject old requests beyond your chosen time window

  • UTC timezone - All timestamps are in UTC

Recommended Time Window

We recommend validating timestamps within a 2-minute window, but you can choose any grace period between 2-5 minutes based on your security requirements and system performance needs.

HTTP Status Codes

Your webhook endpoint must return appropriate HTTP status codes to indicate successful processing

Successful Response

  • 200 OK - Webhook processed successfully

  • Response Time - Must respond within 30 seconds

Important

You must return a 200 status code for the webhook delivery to be considered successful. Any other status code (4xx or 5xx) will cause the webhook to be retried after a certain time interval. Only a 200 response will mark the webhook as delivered and stop the retry process.

What Triggers Retries

  • 4xx Client Errors - Bad request, unauthorized, forbidden, not found, etc.

  • 5xx Server Errors - Internal server error, service unavailable, etc.

  • Timeout - No response within 30 seconds

  • Connection Errors - Network issues, DNS failures, etc.

Retry Behavior

When your endpoint returns a non-200 status code, Clearout will automatically retry the webhook delivery using exponential backoff. The retry schedule depends on your account type. See our Redelivering Webhooksarrow-up-right guide for detailed retry timing information.

Next Steps

Now that you can validate webhook deliveries, learn how to test your webhook integrationarrow-up-right and understand webhook retry behaviorarrow-up-right.

Last updated

Was this helpful?