Signature Validation
This page describes how webhook signatures can be validated to enhance webhook URL security
Signature validation is an optional security step that ensures:
Origin Verification: Ensures the request is actually from 360Dialog and not a malicious third party.
Data Integrity: Guarantees that the webhook payload has not been modified during transit.
We recommend partners perform webhook signature validation to enhance their platform security.
This feature is complementary to the custom webhook URL headers. Custom headers can be used to bypass firewalls or API gateways. Partners can set custom webhook headers and values (e.g., Authorization: <secret>, X-Partner-Auth: <secret>) while setting their webhook URL.
Instructions
360Dialog uses the platform secret to sign the webhook event's body with HMAC-SHA256. The signature is inserted to the request's x-360dialog-signature header. This header is present in every webhook event sent to the partner webhook URL.
The partner must use the platform secret to generate an HMAC-SHA256 signature of the webhook event's body. The signature must be compared with the signature provided in the x-360dialog-signature header using a constant-time algorithm.
If the signatures are identical, continue processing the webhook. If not identical, reject the request.
Rotating platform secret
If the platform secret is leaked, rotate the platform secret immediately.
The platform secret should also be rotated regularly as a best practice. This minimizes the impact of a potential secret compromise.
Make sure to:
Pass platform secret to the server using an environment variable or secret manager.
Protect the platform secret from being leaked by:
Not sending it to the frontend,
Not making it accessible via API,
Using HTTPS for the webhook URL. HTTP connections are insecure and can be intercepted by third-parties on the same network.
Perform signature validation right after receiving a webhook event.
Use constant-time comparison to compare the generated signature with the one in the
x-360dialog-signatureheader. This prevents timing-based attacks.Use deduplication to protect against replay attacks. A webhook event may be captured by a third-party and replayed to the partner webhook URL.
Extract an identifier from the webhook payload, such as its ID,
Check whether that identifier has already been processed,
If it has already been seen, ignore the webhook event and return an HTTP 200 response,
If it has not been seen, enqueue and process it normally, then store the identifier as processed.
Implementation
Implement Deduplication
Webhook signatures do not include a timestamp or nonce. This means a valid signed request could be captured and replayed later by an attacker.
To reduce replay risk, partners should implement a deduplication check based on identifiers in the webhook payload, such as message IDs or other event-specific IDs.
Recommended approach
Validate webhook signature first.
Extract an identifier from the webhook payload, such as its ID.
Check whether that identifier has already been processed.
If it has already been seen, ignore the webhook event and return an HTTP 200 response.
If it has not been seen, enqueue and process it normally, then store the identifier as processed.
Last updated
Was this helpful?