Skip to main content

Validating Webhook Signatures

When you configure a webhook with a signing secret, OpnForm signs each webhook request with an HMAC-SHA256 signature. This allows you to verify that:
  1. The webhook came from OpnForm (authenticity)
  2. The payload hasn’t been modified in transit (integrity)

Understanding the Signature

Each webhook request includes an X-Webhook-Signature header with the format:
The signature is calculated as:
Where:
  • webhook_secret is the secret you provided when creating the webhook
  • request_body is the raw JSON payload

Validation Steps

  1. Extract the signature from the X-Webhook-Signature header
  2. Remove the sha256= prefix
  3. Calculate the expected signature using your webhook secret and the raw request body
  4. Compare the received signature with the calculated signature
  5. Reject the webhook if signatures don’t match
Always use the raw request body (as bytes/string before parsing) when calculating the signature. Parsing JSON and re-serializing can produce different output and cause signature mismatches.

Implementation Examples

Custom Headers

In addition to the signature header, OpnForm will send any custom headers you configured when creating the webhook. These can include authentication tokens, API keys, or other identifiers. Example webhook request with custom headers:
The generic "webhook" integration keeps the legacy submission property for backward compatibility. Provider-specific integrations such as "make" expose the same form_id, form_title, form_slug, submission_id, optional edit_link, and data properties while omitting the deprecated submission and message properties.

Security Best Practices

  1. Use HTTPS only: Always use HTTPS endpoints for webhooks to prevent man-in-the-middle attacks
  2. Strong secrets: Use cryptographically random secrets at least 12 characters long
  3. Constant-time comparison: Use timing-safe comparison functions to prevent timing attacks
  4. Validate signatures first: Verify the signature before parsing or processing the webhook data
  5. Store secrets securely: Never commit secrets to version control; use environment variables or secret managers
  6. Rotate regularly: Consider rotating your webhook secret periodically
  7. Log verification failures: Track failed signature validations to detect potential attacks

Troubleshooting

Signature Mismatch

If you’re consistently getting signature mismatches:
  1. Verify the raw body: Ensure you’re using the raw request body (before JSON parsing) to calculate the signature
  2. Check the secret: Confirm you’re using the exact secret from the webhook configuration
  3. Character encoding: Ensure both the secret and body are handled with correct UTF-8 encoding
  4. Middleware order: If using middleware, ensure raw body capture happens before JSON parsing
  5. Test with cURL: Use the cURL example above to manually test signature generation

Missing Signature Header

If the X-Webhook-Signature header is missing:
  1. Verify you provided a webhook_secret when creating the webhook
  2. Check your webhook status is active
  3. Review the integration event logs for any errors during webhook delivery

Testing Your Webhook

Use a webhook testing service like webhook.site or RequestBin to inspect webhook requests during development. These services display headers, body, and other request details. You can also implement local webhook testing by running a simple server on your machine and using a tool like ngrok to expose it to the internet.