Signature Verification
We include a signature in thex-superleap-signature header of each webhook request. You should verify this signature before processing the webhook payload.
Verification Algorithm
Important: You must stringify the request body with zero whitespace before generating the HMAC signature to ensure a correct match. You can validate your signature verification implementation with the following test code:
sampleJson with the request body and secret_key with your secret key for testing. The output of this code will be:
- The stringified JSON with no whitespace
- The expected signature that should match the one in the
x-superleap-signatureheader
Best Practices
- Always verify signatures: Never skip the signature verification step in production.
- Use environment variables: Store your webhook secret as an environment variable, not in your code.
- Implement idempotency: Process webhooks idempotently to prevent duplicate actions if the same webhook is received multiple times. (Use x-superleap-event-id for the same)
- Respond quickly: Your webhook endpoint should acknowledge receipt of the webhook quickly (2xx status code) and perform any time-consuming work asynchronously.
- Monitor for failures: Implement monitoring to alert you of repeated webhook failures.
- Proper JSON handling: Always stringify JSON with no whitespace (using
null, 0in JavaScript) when calculating signatures to ensure consistency.