Webhook-Signature header for that purpose.
What must be signed?
HMAC signatures are a security measure generated by Helium Id for your webhook listeners to ensure the exchanged data has not been tampered with. When validating a signature on your end, you must recreate the signature using your API Key (acting as the secret) and compare it against theWebhook-Signature header provided in the webhook request.
The Signature Payload
To generate the HMAC signature correctly, you must construct a specific signature string. The payload to sign is a concatenation of the current timestamp and the raw JSON payload body, separated by a period (.).
Format:
timestampis the UNIX epoch time (in milliseconds) extracted directly from theWebhook-Timestampheader sent by Helium Id.payloadis the exact JSON stringified body of the webhook, containing theeventanddataproperties.
Prerequisites
If you want to validate a signature for a webhook request, have the following information at hand:- API Key - Use your Helium Id API Key as the secret key to sign the payload.
- Webhook Payload - The raw JSON body of the webhook.
- Webhook Headers - The
Webhook-TimestampandWebhook-Signatureheaders provided in the request.
Generate and Validate an HMAC Signature
Below are examples showing how to generate an HMAC-SHA256 hash to validate theWebhook-Signature sent by Helium Id.
JavaScript (Node.js) Example
Here is an example in JavaScript of how you can generate the HMAC-SHA256 hash using the built-incrypto module.
Python Example
Here is how you can perform the same validation in Python using the built-inhmac and hashlib libraries.
Go Example
Here is how you can perform the validation in Go using thecrypto/hmac and crypto/sha256 packages.
Best Practices
- Do not expose your API Key: Your API Key is sensitive. Never hardcode it directly into client-side applications. Always store it securely in environment variables.
- Timing Attacks: When comparing the generated signature with the received
x-hmac-signatureheader, use a constant-time string comparison function (likecrypto.timingSafeEqualin Node.js orhmac.compare_digestin Python) to prevent timing attacks. - Timestamp Verification: You can implement a tolerance window (e.g., 5 minutes) by comparing the timestamp in the payload against your server’s current time to protect against replay attacks.