Viewing: Signature Verification

Alerts & Webhooks - Signature Verification

Verify each webhook request signature before processing events in production.

Use the endpoint-specific signing secret (signing_secret) returned when creating the webhook destination.

Delivery headers include X-SAHMK-Signature, X-SAHMK-Event, and X-SAHMK-Event-Id.

  • Each delivery includes X-SAHMK-Signature.
  • Signature generation uses HMAC-SHA256 over the canonical JSON payload. The example sorts keys and removes extra whitespace before signing.
  • Reject mismatches with HTTP 401.
text
# Header format:
# X-SAHMK-Signature: t=<unix_ts>,v1=<hex_hmac>

timestamp, received = parse_signature_header(request.headers["X-SAHMK-Signature"])
canonical_json = json.dumps(payload, sort_keys=True, separators=(",", ":"))
signed_payload = f"{timestamp}.{canonical_json}"
computed = HMAC_SHA256(signing_secret, signed_payload)

if computed != received:
    return 401

process_event(payload)

Replay protection

Timestamp is included in the signature header. Receivers should check that it falls within an accepted window to reduce replay of an older webhook request. Verify the signature and timestamp before processing the event.

Last updated on