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
| Header | Value |
|---|---|
X-Kejue-Signature | sha256= plus 64 lowercase hex characters |
X-Kejue-Timestamp | Unix seconds at signing |
X-Kejue-Delivery-Id | UUID, stable across retries — your dedupe key |
X-Kejue-Attempt | 1-indexed attempt counter |
X-Kejue-Event | The event name |
X-Kejue-API-Version | 2026-07-01 |
X-Kejue-Replayed-From | The 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
- Read the exact raw body bytes, before any JSON parsing.
- Reject timestamps outside your replay window — five minutes is typical.
- Compute
HMAC-SHA256(secret, timestamp + "." + raw_body). - Prefix the lowercase hex digest with
sha256=and compare in constant time. - 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 signatureThe 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.
| Status | Meaning |
|---|---|
pending | Due now, or waiting for its next retry |
running | An attempt is in flight |
success | You returned 2xx |
failed_permanent | A non-retryable response. No further attempts |
exhausted | All 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:
- Deploy your endpoint to accept either the current or the incoming secret.
- Rotate, and store the new secret.
- 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.