ChangeHound

Verifying webhook signatures

Check the X-ChangeHound-Signature header so only genuine alerts reach your code.

When you set a signing secret on a webhook channel, every request carries a header:

X-ChangeHound-Signature: sha256=5d0b0e7c…

The value is the hex HMAC-SHA256 of the raw request body, keyed with your secret.

Checking it

  1. Read the body as bytes before any JSON parsing. Re-serialising the JSON changes whitespace and breaks the signature.
  2. Compute "sha256=" + hex(hmac_sha256(secret, body)).
  3. Compare it to the header with a constant-time comparison (crypto.timingSafeEqual in Node, hmac.compare_digest in Python).
  4. Reject the request with 401 if they differ.

Node.js

const expected = 'sha256=' + crypto.createHmac('sha256', secret).update(rawBody).digest('hex');
const ok = expected.length === header.length && crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(header));

Python

expected = "sha256=" + hmac.new(secret.encode(), raw_body, hashlib.sha256).hexdigest()
ok = hmac.compare_digest(expected, header)

Rotating the secret

Add a second webhook channel with the new secret, deploy code that accepts either, remove the old channel, then drop the old secret. Treat change.id as an idempotency key: retries can deliver the same change more than once.

Was this article helpful?