Secure your project's, task's, and issue's webhooks with HMAC-SHA 256 (Hash-Based Message Authentication Codes with SHA 256). Zoho Projects has the option to secure webhooks using HMAC-SHA 256, an industry standard hashing mechanism to ensure and maintain the authenticity and integrity of webhooks.
HMAC helps check:
- If the webhook request has been sent from Zoho Projects (The secret key must be known only to Zoho Projects and the receiving application).
- If the webhook content has been tampered with along the way.
Why secure Webhooks?
Webhooks are HTTP requests of one application to provide real-time data to another application. In a security attack, the attackers can easily impersonate legitimate providers by sending fraudulent webhooks and extracting sensitive data. Therefore, webhooks need to be secure so that your app only listens to real events from trusted sources and doesn’t get tricked by fake or harmful requests.
Benefits:
- Avoid wrong data in reports
- Avoid unauthorized updates
- Avoid security breaches
Enable Webhook security
Users can enable webhook security setting while adding or editing a webhook.
- Go to Settings > Automation/ Issue Tracker > Webhooks.
- For new webhooks, fill in the details in the webhook form and toggle Security Settings. For existing webhooks, select the webhook where you want to enable security.
- Enter the HMAC key. Users can also generate HMAC key by clicking on Generate.
- Click Save.
HMAC key length should be between 16 to 128 characters long.
How does webhook security work in Zoho Projects?
When a webhook is sent from Zoho Projects, an HMAC signature is included in the request headers with the name X-ZP-WEBHOOK-SIGNATURE. Upon receiving the webhook request, the receiving application will generate a HMAC signature using the same secret key and compare the results with the value present in the request header. If the value matches, the data is legitimate; otherwise, the data has been tampered with.
Generating a HMAC signature
Zoho Projects calculates the signature of the webhook payload using the HMAC-SHA256 algorithm, and the result is sent in base64 format in the request header. Here is the explanation with sample data:
payload | {{"requests":{"request_name":"Test Name"},"notifications": {"operation_type":"RequestSigningSuccess"}} |
secret_key | thisisthesamplekeyfortestingpurposes |
base64encode(HMAC SHA-256(payload+secret_key)) | drbSrM4H816RYKpZiRBLddUa0yHaTrwjtY04sIZFZus=
|
Here is an image of how webhook request header(HMAC header) look like:
Verifying HMAC signature in the receiving application
- You must read the payload as a string to avoid reordering keys when read in JSON format.
- Compute HMAC SHA-256 hash of the payload using the secret key and base64 encode the result.
- Compare the value obtained from step 2 and the received HMAC header (X-ZP-WEBHOOK-SIGNATURE) value. If there is a mismatch, reject the webhook request.
A sample of Java code snippet to verify the HMAC signature: