Developer Docs
English
English
Each webhook is signed with HMAC-SHA256 using a webhookSecret unique to your organisation. Your endpoint must recompute the signature to confirm the event is authentic.
HMAC-SHA256( secret, rawBody + timestamp ) → hex → Base64| Header | Description |
|---|---|
zb-timestamp | Unix milliseconds at send time |
zb-signature | Signature generated by Zertiban |
Sign the body exactly as received
Zertiban signs the body exactly as it sends it: compact JSON, with no whitespace or line breaks, and the keys in the order they travel in, which is not alphabetical. Compute the signature over the bytes you receive, without parsing the JSON, re-serializing it or converting it to text. Reordering the keys, adding whitespace or escaping characters such as ñ (\u00f1) yields a different signature.
rawBody + zb-timestamp, using the header value exactly as received.HMAC-SHA256(webhookSecret, step2) over the UTF-8 bytes → binary digest.hex(digest) → bytes → Base64 = expected value of zb-signature.import org.apache.commons.codec.binary.Hex;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Base64;
// rawBody: the body bytes exactly as received, not parsed or converted to a String
public boolean isValidWebhook(byte[] rawBody, String timestamp,
String signature, String secret) throws Exception {
if (rawBody == null || timestamp == null || signature == null) {
return false;
}
// 1. HMAC-SHA256 of message = raw body + timestamp
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
mac.update(rawBody);
byte[] digest = mac.doFinal(timestamp.getBytes(StandardCharsets.UTF_8));
// 2. hex → Base64
String expected = Base64.getEncoder()
.encodeToString(Hex.encodeHexString(digest)
.getBytes(StandardCharsets.UTF_8));
return MessageDigest.isEqual(
expected.getBytes(StandardCharsets.UTF_8),
signature.getBytes(StandardCharsets.UTF_8));
}
// Spring: take the body as @RequestBody byte[], not as a String or a DTOconst crypto = require('crypto');
// rawBody: the body exactly as received, as a Buffer, no JSON.parse
function isValidWebhook(rawBody, timestamp, signature, secret) {
if (!rawBody || !timestamp || !signature) return false;
const hex = crypto.createHmac('sha256', secret).update(rawBody).update(timestamp).digest('hex');
const expected = Buffer.from(Buffer.from(hex).toString('base64'));
const received = Buffer.from(signature);
// timingSafeEqual throws if the lengths differ
return expected.length === received.length && crypto.timingSafeEqual(expected, received);
}
// Express: use express.raw({ type: 'application/json' }) on the webhook route, not express.json()import hmac, hashlib, base64
# raw_body: the body exactly as received, as bytes, no json.loads
def is_valid_webhook(raw_body, timestamp, signature, secret):
if not raw_body or not timestamp or not signature:
return False
digest = hmac.new(
secret.encode(), raw_body + timestamp.encode(), hashlib.sha256
).digest()
expected = base64.b64encode(digest.hex().encode())
return hmac.compare_digest(expected, signature.encode())
# Flask: use request.get_data() to read the raw body as byteshmac.compare_digest, MessageDigest.isEqual, crypto.timingSafeEqual) to avoid timing attacks.401 or 403, don't process the event, and log the attempt for auditing.zb-timestamp is within ±5 minutes to prevent replay attacks.| Cause | Solution |
|---|---|
| Body parsed, reformatted or converted to text before verification | Use the raw bytes: express.raw() in Express, request.get_data() in Flask, @RequestBody byte[] in Spring |
Wrong webhookSecret | Confirm the secret with Zertiban |
webhookSecret decoded | Use it as is, as text. Even if it looks like Base64, don't decode it |
| Missing hex→Base64 step | The algorithm is HMAC → hex → Base64, not HMAC → Base64 directly |
zb-timestamp omitted | Always concatenate rawBody + timestamp, in that order, before the HMAC |
Cleanly separate the four phases of webhook consumption:
This yields consumers that are idempotent, auditable, and resilient to retries, decoupled from business processing.