| Parameter | Description |
|---|---|
x-webhook-signature | HMAC SHA256 signature generated by Cashfree. |
x-webhook-timestamp | Timestamp of when the webhook was generated. |
| Request body | The actual webhook payload. |
Verification flow
To validate the webhook:Capture headers and raw payload
- Read
x-webhook-signaturefrom request headers. - Read
x-webhook-timestampfrom request headers. - Capture the raw request body.
Generate HMAC SHA256 signature
- Use your webhook secret key.
- Apply HMAC SHA256 hashing on
signatureData.
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.