Circularo webhooks are a great tool to get real-time or near-real-time information about events that happen in the system. When compared to approaches such as polling, webhooks greatly reduce the computational and implementation costs for the integration and guarantee almost immediate processing after an event is triggered.
However, because webhooks are essentially public HTTP endpoints, they are vulnerable to “spoofing” – malicious attacks where an actor mimics a Circularo request to trigger unauthorized actions in your system.
To combat this, Circularo supports HMAC (Hash-based Message Authentication Code) signatures, providing a robust layer of security for your integrations.
Why use HMAC for your webhooks?
While setting an HMAC secret is optional for Circularo webhooks, it is highly recommended for any production environment. Using HMAC ensures two critical security properties:
- Authenticity: You can prove the request actually came from Circularo and not from an impostor
- Integrity: You can verify that the data in the request body hasn’t been tampered with during transit
How it works
When you provide an HMAC secret in your Circularo webhook setup, Circularo uses that secret to create a unique hash of the request body. This hash is then sent along with the webhook in a custom HTTP header: x-circularo-signature.
Note: The signature is generated using the SHA-256 algorithm and is provided in hexadecimal format
Generating your HMAC secret
To get started with HMAC, you first need to generate a secure secret. Think of this secret as a shared password between Circularo and your application. It should be a cryptographically strong random string to ensure it cannot be easily guessed or brute-forced.
Format and generation
While Circularo accepts standard string formats, it is a best practice to use a string at least 32 characters (256 bits) long. For maximum security, you can generate a random hex string using your terminal:
# Generate a secure 32-byte hex secret
openssl rand -hex 32
Where to set it
Once you have your secret, you can add it to your webhook configuration in the Circularo Administration or via the API call by populating the hmacSecret field.
Important Security Tip: Treat your HMAC secret like a private key. Store it in an environment variable or a secret management service (like AWS Secrets Manager) rather than hardcoding it into your application. If you believe your secret has been compromised, you should rotate it immediately in both Circularo and your application.
Implementation: security verification
To secure your endpoint, your application should calculate its own signature using the same secret and the raw request body, then compare it to the signature provided by Circularo. If they don’t match, the request should be rejected.
Here is an example of how to implement this verification in a Node.js environment:
// Example verification in Node.js
const crypto = require('crypto');
function verifyWebhookSignature(requestBody, signature, secret) {
// Create an HMAC object using the SHA-256 algorithm and your secret
const hmac = crypto.createHmac('sha256', secret);
// Update the HMAC with the raw request body and generate the hex digest
const calculatedSignature = hmac.update(requestBody).digest('hex');
// Compare the calculated signature with the one from the 'x-circularo-signature' header
return calculatedSignature === signature;
}
Best practices for development and production
- Testing: During development, you can use services like NGrok to inspect the headers and payloads being sent by Circularo. You can refer to our guide on how to use NGrok for further information
- Production readiness: Ensure your production endpoint is optimized to handle the expected volume of webhook events
- Secret management: Never hardcode your HMAC secret. Use environment variables (.env) or a secure vault to store it, and ensure it is never exposed in client-side code. Never commit your secret to a version control system
Conclusion
By implementing HMAC verification, you transform your webhook endpoint from a potential entry point for attackers into a secure Circularo automation.
For more technical details, visit the Circularo Developer Documentation.
In our next article, we will have a look at how to check the document status and implement a polling mechanism – an alternative to using webhooks.







