Request Verification

Webhook Requests Signature Verification

To ensure the integrity and authenticity of webhook requests sent from our system, we include a signature in each request. This allows you to verify that the request originated from us and that the payload has not been tampered with.

This process is similar to how GitHub secures its webhook deliveriesarrow-up-right.

Signature Header

Each webhook request will include an X-Lucra-Signature HTTP header. This header contains a hexadecimal HMAC (Hash-based Message Authentication Code) signature of the request payload.

Get Your Webhook Record Secret

Once a webhook is registered with your server URL, use the webhook id to request the shared secret from your Lucra representative. This will be shared through a secure method like, for example, single share secret links.

Generating the Signature (Our Side)

When an event triggers a webhook call to your configured URL, our system generates the signature for the X-Lucra-Signature header. This is done by calculating an HMAC (e.g., HMAC-SHA256) of the raw JSON request body using the unique shared-secret associated with your specific webhook configuration. The resulting hexadecimal digest is then formatted and sent as the header value.

Verifying the Signature (Your Side)

To verify the signature on your end, you need to perform a similar calculation and compare the result with the signature we sent.

Steps to Verify:

  • Extract the Signature: Get the value of the X-Lucra-Signature header from the incoming request.

  • Prepare the Payload: Use the raw request body. It's crucial to use the exact same byte sequence that we used to generate the signature. Do not parse and then re-stringify the JSON, as this might alter its structure (e.g., whitespace, key order) and result in a mismatched signature.

  • Retrieve Your Shared Secret: Obtain the shared-secret that is created upon webhook registration from your Lucra representative.

  • Calculate the Expected Signature: Compute the HMAC of the raw request body using the identified algorithm and your shared-secret.

  • Compare Signatures: Compare the signature extracted from the X-Lucra-Signature header with the expected signature you just calculated. They must be an exact match. To prevent timing attacks, use a constant-time string comparison function.

Important Considerations:

  • Transactional Events: For events that are considered as transactional, this verification is crucial as these events can only be configured for a single endpoint. A successful verification ensures that critical transactional data is processed securely and correctly.

  • Shared Secret Management: Keep your shared-secret confidential. Treat it like a password. If a secret is compromised, you should generate a new configuration record and delete the compromised one, get in contact with your Lucra representative to get your new secret and update your verification logic accordingly.

  • Raw Body: Always use the raw request body for signature calculation. Many web frameworks provide access to the raw body before any parsing occurs.

Examples

Let's assume the hashing algorithm is HMAC-SHA256 and the header format is sha256=.

Example Shared Secret: yourSecretToken123

Example Request Body (raw JSON):

Signature Verification:

This example uses Node.js and its built-in crypto module.

Last updated