TraceTrace
Webhooks

Verify webhook signatures

Authenticate Trace webhook requests using the raw body and HMAC-SHA256.

Trace signs the exact request body with the secret issued for that subscription.

HeaderPurpose
sterling-webhook-idStable delivery ID for idempotency.
sterling-webhook-timestampUnix timestamp used in the signed message.
sterling-webhook-signaturev1= followed by the lowercase hexadecimal digest.
HMAC-SHA256 verification
1signed_payload = sterling-webhook-timestamp + "." + raw_body
2expected = HMAC-SHA256(webhook_secret, signed_payload)
3received = sterling-webhook-signature.removeprefix("v1=")

Verification order

  1. Read the raw request bytes before parsing JSON.
  2. Reject a timestamp outside your replay window; five minutes is a practical default.
  3. Join the timestamp, a period, and the raw body.
  4. Compute HMAC-SHA256 with the subscription secret.
  5. Compare the received and expected hex digests with a timing-safe function.
  6. Record sterling-webhook-id, then acknowledge duplicates with 2xx without repeating their side effects.

Parsing and re-serializing JSON changes the signed bytes and causes a valid request to fail verification.

On this page