Steps to Generate the Webhook Signature
1. Extract the event_id
The event_id is a unique identifier for each webhook event. It is part of the webhook request payload.
Example of how event_id is structured:
2. Extract the Timestamp
The time when the webhook request was received. Extract the created_at field from the webhook response. Please note that we need to extract thecreated_at field that is outside the data json block. The timestamp will be in RFC3339Nano format.
json
3. Concatenate Data for Signing
Once you have the event_id and the timestamp, you need to concatenate them with the payload into a single string. This concatenated string will be used to generate the signature.json
Generate HMAC-SHA256 Signature
Once you have concatenated the data, you will use HMAC-SHA256 to generate the signature. HMAC (Hash-based Message Authentication Code) is a cryptographic function that ensures data integrity and authenticity by using a secret key and a hashing algorithm. To generate the signature:- Concatenate the event_id, payload, and timestamp into a single string.
- Use HMAC-SHA256 to hash the concatenated string using your secret key.
- You can find the secret key on the merchant dashboard on the Settings > Webhooks > secret token. Click on reveal to view the secret token
- Generate the signature in Base64 format.
YKzhhJM4gd8s5MS1LVvWbqSyJqLPvr7j -
Verify the signature
Once you have generated the signature on your end, you can match it with the signature sent by Tazapay in the webhook header in the field name -signature. If both of the signatures match , that means that the webhook is sent by Tazapay and has not been tampered with while transmission.
Avoiding Replay Attacks
A replay attack occurs when an attacker intercepts a valid payload and its signature, then retransmits them. To mitigate such attacks, Tazapay includes a timestamp in thesignature header. Since this timestamp is part of the signed payload, it is also verified through the signature. This ensures that an attacker cannot modify the timestamp without invalidating the signature.
If the signature is valid but the timestamp is too old, your application should reject the payload. You can allow a tolerance of 10 minutes between the timestamp and the current time to avoid replay attacks.