Verifying webhook signatures
Every iChatUp webhook carries an X-iChatUp-Signature header of the form sha256= followed by a hex HMAC-SHA256 of the raw request body, keyed with your account’s webhook secret. To verify a call, compute the same HMAC over the exact bytes you received, add the prefix, and compare the two in constant time. Reject the request when they differ.
Sepintas lalu
| Header | X-iChatUp-Signature: sha256=… |
|---|---|
| Algorithm | HMAC-SHA256, hex digest |
| Signed content | The raw JSON body, byte for byte |
| Secret | Integrations page, “For your developer”; starts with whsec_ |
Node.js
const crypto = require("crypto");
function isFromIchatup(rawBody, header, secret) {
const expected = "sha256=" +
crypto.createHmac("sha256", secret).update(rawBody).digest("hex");
const a = Buffer.from(expected);
const b = Buffer.from(header || "");
return a.length === b.length && crypto.timingSafeEqual(a, b);
}
// Express: app.post("/ichatup", express.raw({ type: "application/json" }), ...)
// then isFromIchatup(req.body, req.get("X-iChatUp-Signature"), process.env.ICHATUP_WEBHOOK_SECRET)
PHP
$raw = file_get_contents("php://input");
$expected = "sha256=" . hash_hmac("sha256", $raw, getenv("ICHATUP_WEBHOOK_SECRET"));
$given = $_SERVER["HTTP_X_ICHATUP_SIGNATURE"] ?? "";
if (!hash_equals($expected, $given)) {
http_response_code(401);
exit;
}
$event = json_decode($raw, true);
Common mistakes
- Hashing parsed JSON. Re-encoding the body changes spacing and escaping, so the HMAC will not match. Hash the raw bytes.
- Forgetting the prefix. The header value includes
sha256=. - Comparing with ==. Use a constant-time comparison.
- Trusting old calls. The signature does not cover a timestamp, so also de-duplicate on
X-iChatUp-Deliveryand ignore events whoseoccurred_atis far in the past.
Keep the secret on your server, like an API key. Event fields are listed in webhook events.
Soalan lazim
When is the secret created?
The first time a webhook address is saved. It then stays the same, and the Integrations page shows it under “For your developer”.
Is the test lead signed too?
Yes. The “Send a test lead” button signs it with the same secret, so you can test verification with it.
Cuba pada nombor anda sendiri
Dua minit untuk sambung, 7 hari percuma, tanpa kad. Pekerja AI anda menjawab, membuat tempahan dan membuat susulan di nombor WhatsApp yang sudah digunakan pelanggan anda.