Verifying Webhook Authenticity
To ensure webhooks are coming from Speckle and haven’t been tampered with, you should verify the webhook signature using the secret you configured. The webhook signature is sent in theX-WEBHOOK-SIGNATURE header. The signature is computed using HMAC-SHA256 with your webhook secret.
Example Verification
Avoiding Infinite Loops
Best Practices
1. Use HTTPS Endpoints
Always use HTTPS for your webhook endpoints to ensure payloads are encrypted in transit.2. Verify Signatures
Always verify webhook signatures to ensure requests are authentic and haven’t been tampered with.3. Handle Failures Gracefully
Webhook delivery is not guaranteed. Implement retry logic and handle failures appropriately:- Return appropriate HTTP status codes (200-299 for success)
- Log failed deliveries for debugging
- Consider implementing a dead letter queue for failed webhooks
4. Process Asynchronously
Webhook handlers should process requests asynchronously and return quickly:- Acknowledge receipt immediately (return 200 OK)
- Process the webhook data in a background job
- Avoid long-running operations in the webhook handler
5. Idempotency
Make your webhook handlers idempotent to handle duplicate deliveries:- Use event IDs or timestamps to detect duplicates
- Store processed event IDs to prevent reprocessing
6. Rate Limiting
Be aware of rate limits on your webhook endpoint. If you receive many events, consider:- Batching multiple events
- Using a message queue to buffer events
- Scaling your endpoint to handle the load
Frequently Asked Questions
How do I verify webhook signatures?
How do I verify webhook signatures?
Use HMAC-SHA256 to compute a signature from the webhook payload and your secret, then compare it with the
X-WEBHOOK-SIGNATURE header. See the Example Verification section above for code examples in Node.js and Python.What happens if I don't verify signatures?
What happens if I don't verify signatures?
Without signature verification, your endpoint could accept fake webhook requests from attackers, potentially leading to security vulnerabilities, data corruption, or unauthorized actions in your system. Always verify signatures in production.
Can I use webhooks without a secret?
Can I use webhooks without a secret?
Yes, secrets are optional, but highly recommended for production use. Without a secret, you cannot verify that webhooks are actually coming from Speckle, leaving your endpoint vulnerable to spoofed requests.
How do I handle webhook failures gracefully?
How do I handle webhook failures gracefully?
Implement proper error handling:
- Return appropriate HTTP status codes (200-299 for success)
- Log failures for debugging
- Use idempotency to handle duplicate deliveries
- Process webhooks asynchronously to avoid timeouts
- Consider a dead letter queue for persistent failures
What HTTP status codes should my webhook endpoint return?
What HTTP status codes should my webhook endpoint return?
Return status codes in the 200-299 range to indicate successful receipt. Speckle considers any other status code as a failure and may retry the delivery. Return 200 OK immediately, then process the webhook asynchronously in the background.
How do I prevent duplicate webhook processing?
How do I prevent duplicate webhook processing?
Make your webhook handlers idempotent by:
- Using event IDs or timestamps to detect duplicates
- Storing processed event IDs in a database or cache
- Checking if an event has already been processed before acting on it
How do I avoid infinite loops with webhooks?
How do I avoid infinite loops with webhooks?
If your webhook handler creates a new version/commit, it will trigger another webhook event, potentially creating an infinite loop. To prevent this:
- Always check if changes are actually needed before creating new versions
- Use conditional logic to exit early when no action is required
- Implement idempotency checks to avoid reprocessing the same event
- Monitor for unusual activity patterns