Securing Zoho Sign Webhooks with HMAC authentication

Webhooks Security

Zoho Sign lets you secure your webhooks in two ways: by authenticating the requests sent to your endpoint (confirming they come from Zoho Sign) and by verifying the integrity of each payload (confirming it hasn't been tampered with). You can configure both under Security Settings when you create or edit a webhook, and you can combine them for stronger protection.

Authentication

Authentication methods confirm who is calling your endpoint. Enable one or more under Settings > Developer Settings > Webhooks > Security Settings > Authentication.

Basic Authentication

You can protect your webhook endpoint with a username and password using HTTP Basic Authentication. To do this, enable Basic Authentication and enter the username and password your endpoint will validate against. 

Note: The credentials are Base64-encoded and sent in the Authorization header with every webhook request.

Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

// How the Basic Auth header is constructed:

credentials = "username:password"

encoded = base64(credentials)

header = "Basic " + encoded

OAuth 2.0

Authenticate your webhook using OAuth 2.0. Zoho Sign fetches an access token from your token URL using the Client Credentials grant, then sends it as a Bearer token in the Authorization header with every webhook request.

  1. Enable OAuth 2.0 and select the Provider.
  2. Enter the Token URL, Client ID, and Client Secret.
  3. (Optional) Enter a Scope.
  4. (Optional) Under Additional Parameters, add any custom name/value pairs to be sent as-is in the token request body (for example, audience). Click the + icon to add more.
Notes
Note: OAuth 2.0 and Basic Authentication cannot be enabled together; enabling one disables the other.

Example authorization header:

Authorization: Bearer <access_token>

// The access token is fetched from the Token URL via the Client Credentials

// grant using the Client ID/Secret, and cached until it expires.

Mutual TLS (mTLS)

You can authenticate your webhook endpoint using client certificates for mutual TLS verification. To do this, enable Mutual TLS (mTLS) and provide your certificate in one of two formats:
  1. Client Certificate (.pem) and Private Key (.pem / .key), plus the Key password if your key is encrypted; (or)
  2. A PFX / P12 Certificate file, plus its Key password.
Notes
Note: Only one of the two formats of the client certificates can be active at a time.

Custom Request Headers

You can attach custom HTTP headers to every webhook request for additional authentication or routing.

To do this:
  1. Enable Custom Request Headers and enter a Header Name and Header Value.
  2. To add another header, click the + icon. You can add up to five custom headers.

Integrity

Integrity options confirm that the payload is genuine and unaltered. Configure them under Settings > Developer Settings > Webhooks > Security Settings > Integrity.

HMAC signature

When a webhook is sent from Zoho Sign, a HMAC signature will be included in the request headers with the name X-ZS-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. Zoho Sign 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 this webhook request header (HMAC header) will look like:


Verifying HMAC signature in the receiving application

  1. You must read the payload as a string to avoid reordering keys when read in JSON format.
  2. Compute HMAC SHA-256 hash of the payload using the secret key and base64 encode the result.
  3. Compare the value obtained from step 2 and the received HMAC header (X-ZS-WEBHOOK-SIGNATURE) value. If there is a mismatch, reject the webhook request.


Sample java cope snippet to verify the HMAC signature

  1.     private static String verifyHmacHash(String secretKey, String payload, String hmacHash) throws Exception 
  2.     {
  3.         String macAlgoName = "HmacSHA256";
  4.         byte[] secretKeyBytes = secretKey.getBytes(StandardCharsets.UTF_8);
  5.         Mac mac = Mac.getInstance(macAlgoName);
  6.         SecretKeySpec keySpec = new SecretKeySpec(secretKeyBytes, mac.getAlgorithm());
  7.         mac.init(keySpec);
  8.         byte[] macData = mac.doFinal(payload.getBytes(StandardCharsets.UTF_8));
  9.         String calculatedHmac = java.util.Base64.getEncoder().encodeToString(macData);
  10.         
  11.         if(hmacHash.equals(calculatedHmac))
  12.         {
  13.         System.out.println("Hashes match, Webhook payload is valid!!");
  14.         }
  15.         else
  16.         {
  17.         System.out.println("Hashes doesn't match, Webhook payload is tampered!!");
  18.         }
  19.         return calculatedHmac;
  20.     }

Timestamp

Enable a timestamp to help prevent replay attacks, where a valid request is captured and resent later.
  1. Under Integrity, enable Enable timestamp.
  2. Zoho Sign will add an X-ZS-WEBHOOK-TIMESTAMP header to each request, alongside the X-ZS-WEBHOOK-SIGNATURE header.
  3. In your application, reject requests whose timestamp falls outside a short tolerance window, and include the timestamp when verifying the HMAC signature.
Example request headers:
x-zs-webhook-timestamp: 1704067200

X-ZS-WEBHOOK-SIGNATURE: 5d41402abc4b2a76b9719d911017c592
Notes
Note: When timestamp is enabled, a ready-to-use verification code sample is shown on the webhook configuration screen.