Skip to Content

Verifying deliveries

Check the signature before you trust a webhook, handle retries and duplicates, and rotate the secret safely.

Anyone can POST JSON to your endpoint. Verify our signature before you act on a delivery — and treat a verification failure as "not from us", not as an error to retry.

Headers

HeaderValue
X-Kejue-Signaturesha256= plus 64 lowercase hex characters
X-Kejue-TimestampUnix seconds at signing
X-Kejue-Delivery-IdUUID, stable across retries — your dedupe key
X-Kejue-Attempt1-indexed attempt counter
X-Kejue-EventThe event name
X-Kejue-API-Version2026-07-01
X-Kejue-Replayed-FromThe original delivery's UUID, on replays

Every delivery also carries the same values as X-Sonus-* headers, so existing verifiers keep working. It's one delivery with two header families, not two events — pick one family and dedupe by delivery ID.

Verify the signature

  1. Read the exact raw body bytes, before any JSON parsing.
  2. Reject timestamps outside your replay window — five minutes is typical.
  3. Compute HMAC-SHA256(secret, timestamp + "." + raw_body).
  4. Prefix the lowercase hex digest with sha256= and compare in constant time.
  5. Process each delivery ID at most once.
import hashlib
import hmac
import time

def verify_kejue_webhook(headers, raw_body: bytes, secret: str) -> bool:
    headers = {key.lower(): value for key, value in headers.items()}
    prefix = "x-kejue-" if "x-kejue-signature" in headers else "x-sonus-"
    timestamp = headers.get(prefix + "timestamp")
    signature = headers.get(prefix + "signature")
    if not isinstance(timestamp, str) or not isinstance(signature, str):
        return False
    try:
        if abs(time.time() - int(timestamp)) > 300:
            return False  # stale or future-dated
    except ValueError:
        return False
    digest = hmac.new(
        secret.encode(),
        timestamp.encode() + b"." + raw_body,
        hashlib.sha256,
    ).hexdigest()
    try:
        return hmac.compare_digest("sha256=" + digest, signature)
    except TypeError:
        return False  # malformed, non-ASCII signature

The signature covers the exact bytes we sent. If your framework parses the JSON and you re-serialize it, the key order or whitespace will differ and the signature won't match. Capture the raw body.

Respond 2xx quickly and do the slow work afterwards. Anything else and we'll retry.

Retries

Any 2xx is a success. A failure retries up to seven attempts over roughly 31 hours — after 1 minute, 5 minutes, 15 minutes, 1 hour, 6 hours, and 24 hours.

We retry network failures, timeouts, 408, 425, 429, and any 5xx, and we honour your Retry-After up to 24 hours. Any other 4xx is permanent — no retry.

Each attempt is signed fresh, but the body is the one snapshotted at the first attempt. Dedupe on the delivery ID, not on content.

StatusMeaning
pendingDue now, or waiting for its next retry
runningAn attempt is in flight
successYou returned 2xx
failed_permanentA non-retryable response. No further attempts
exhaustedAll seven attempts used

Resend an exhausted or failed_permanent delivery with POST /v1/webhook-deliveries/{id}/replay.

Rotating the secret

Rotating returns a new secret once, and the old one stops signing immediately — including retries of deliveries that were first attempted before the rotation. So:

  1. Deploy your endpoint to accept either the current or the incoming secret.
  2. Rotate, and store the new secret.
  3. Once deliveries verify against the new secret, drop the old one.

If a secret leaks, rotate first and clean up after. A short window of rejected deliveries is recoverable by replay; a forged delivery that your endpoint accepted as verified is not.

See also

Webhooks · Webhook payloads

On this page