---
title: "Verify iChatUp Webhook Signatures (HMAC-SHA256)"
url: https://ichatup.com/docs/webhook-signatures
description: "Check that a webhook really came from iChatUp: recompute the HMAC-SHA256 of the raw body with your secret and compare it with X-iChatUp-Signature."
source: iChatUp
---

Developers

# 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.

## At a glance

|  |  |
| --- | --- |
| 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-Delivery` and ignore events whose `occurred_at` is far in the past.

Keep the secret on your server, like an API key. Event fields are listed in [webhook events](https://ichatup.com/docs/webhook-events).

## Questions

**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.

## Read next

- [Webhook events](https://ichatup.com/docs/webhook-events)
- [Webhooks](https://ichatup.com/works-with/webhooks)
- [Security & trust](https://ichatup.com/security)
- [Authentication](https://ichatup.com/docs/authentication)

---
Source: https://ichatup.com/docs/webhook-signatures
