To validate the webhook, verify the signature using your webhook secret key.
Verification flow
To validate the webhook:1
Capture headers and raw payload
- Read
x-webhook-signaturefrom request headers. - Read
x-webhook-timestampfrom request headers. - Capture the raw request body.
2
Create signature data
Concatenate the timestamp and raw request body:
3
Generate HMAC SHA256 signature
- Use your secret key.
- Apply HMAC SHA256 hashing on
signatureData.
4
Encode signature
Encode the hash as a Base64 string.
5
Compare signatures
Compare the computed signature with the received signature:
- If matched: Webhook is valid.
- If not matched: Reject the request.
Sample implementations
Select your language or framework to view a sample implementation.Node.js (Express)
Node.js (Express)
Node.js
Python (Flask)
Python (Flask)
Python
Go
Go
Go
PHP
PHP
PHP
Java
Java
Java
C# (.NET)
C# (.NET)
C#
Security requirements
Keep the following requirements in mind when implementing webhook signature verification.- Always use the raw request body for signature computation.
- Don’t modify, parse, or reformat the payload before verification.
- Store your webhook secret key securely. Use environment variables.
- Reject webhook requests if signature mismatch occurs or required headers are missing.
Best practices
Use these practices to improve the security and reliability of your webhook implementation.- Validate timestamp to prevent replay attacks (recommended window: 5 minutes).
- Log invalid webhook attempts for debugging and monitoring.
- Process webhook events only after successful signature verification.
Summary
The verification process covers the following steps:- Capture the
x-webhook-signatureandx-webhook-timestampheaders along with the raw request body. - Concatenate the timestamp and raw body to form the signature data.
- Generate an HMAC SHA256 hash using your webhook secret key.
- Encode the hash as a Base64 string.
- Compare the computed signature with
x-webhook-signature. If they match, the webhook is valid. If they don’t match, reject the request.