WebhooksSecurityAPIGuide

Webhook Signature Verification: HMAC-SHA256, and Why the Timestamp Matters

How webhook signature verification works: HMAC-SHA256 over the raw body, constant-time compare, and a signed timestamp that stops replays. TypeScript examples.

Written by: Zavu TeamReviewed by: Jennifer VillalobosNovember 25, 202610 min read
View as Markdown

Your webhook URL is public. It has to be.

Anyone who finds it can send it a POST. A fake message.inbound. A fake "payment confirmed". Or a real request someone captured last week, sent again.

Your server cannot tell the difference unless every request carries proof. That proof is a signature, and half of it is a clock.

Webhook signature verification is the check your server runs to confirm a webhook came from the provider and was not modified on the way. The provider signs the request with a shared secret, almost always with HMAC-SHA256, and your server recomputes the signature and compares.

TL;DR

  • A webhook signature is an HMAC. The sender hashes the request with a shared secret; you recompute the hash and compare. HMAC is defined in RFC 2104 (February 1997).
  • Hash the raw bytes. Parse the JSON and serialize it again and the bytes can change, so the signature stops matching.
  • Compare in constant time. crypto.timingSafeEqual in Node. Never === or ==.
  • Sign the timestamp too. A signature over the body alone stays valid forever, so a captured request can be replayed. Zavu's v2 scheme signs {t}.{body}, and you reject anything older than five minutes.
  • Still deduplicate. Zavu retries failed deliveries, and each retry carries a fresh, valid signature. Store event.id.
  • In Zavu, new webhooks use v2. Older ones stay on v1 until you move them: no deadline, three steps, no downtime.

What is webhook signature verification?

A webhook is someone else's server calling yours. So the first question is not "what happened?". It is "who is asking?".

Signature verification answers that with a shared secret:

  • When you create the webhook, the provider gives you a secret. In Zavu it looks like whsec_... and is returned only when the webhook is created or the secret is regenerated.
  • On every delivery, the provider computes HMAC_SHA256(secret, payload) and sends it in a header.
  • Your server computes the same HMAC over what it received.
  • If the two match, the request came from someone who holds the secret, and nobody changed a byte along the way.
  • That is all HMAC is. RFC 2104 describes it as "a mechanism for message authentication using cryptographic hash functions", used "in combination with a secret shared key". It is almost thirty years old, and it still holds.

    What does Zavu send?

    Every Zavu webhook carries one header:

    X-Zavu-Signature: t=1786113454,v2=b4b2b61cdcdb241e4270298a08c3c13c964642df...
    PartMeaning
    tUnix timestamp in seconds, when the signature was generated
    v1HMAC_SHA256(secret, body)
    v2HMAC_SHA256(secret, "{t}.{body}")

    A header carries v1, v2, or both. Which one you get is set per receiver, and you control it.

    Compare that with Meta's own WhatsApp webhooks. Meta sends X-Hub-Signature-256: sha256=, an HMAC-SHA256 of the payload keyed with your app secret. Same primitive, with the body as the only input. That is a valid design. It just leaves the "when" to you.

    Why does the timestamp matter?

    Here is the quiet problem with signing only the body: a body-only signature proves the body is authentic. It does not prove the request is new.

    If someone captures one valid delivery (from a log, a proxy, a debug tool left on), they can send it again tomorrow. Same body, same signature, still valid.

    The obvious fix is "check the timestamp". But under a body-only scheme the timestamp is not covered by the signature. An attacker rewrites t to the current second, and the signature still matches.

    That is the whole difference between Zavu's two schemes:

    v1v2 (current)
    What is signedThe body{t}.{body}
    Is t protected?No. It is in the header but not signedYes. Change it and the signature breaks
    Does a 5-minute window stop a replay?No, because t can be rewrittenYes. An old t fails the age check, a new t fails the signature
    Who has itWebhooks created before the scheme was configurableEvery new webhook
    Deadline to moveNone—

    With v2, the timestamp check carries weight. With v1, it is decoration.

    Zavu's docs set the window like this:

    • Reject a request if t is more than 300 seconds (five minutes) old.
    • Reject it if t is more than 60 seconds in the future (clock skew, or forged).
    • Recompute with the t from the header, not your own clock.

    How do you verify a Zavu webhook in Node.js / TypeScript?

    Four steps, in this order: read the raw body, parse the header, check the timestamp, recompute and compare.

    TypeScript
    import crypto from "node:crypto"; import express from "express"; const app = express(); const SECRET = process.env.ZAVU_WEBHOOK_SECRET!; const MAX_AGE_SECONDS = 300; // reject anything older than five minutes const MAX_FUTURE_SECONDS = 60; // small allowance for clock skew export function verifyZavuSignature(rawBody: string, header: string | undefined, secret: string): boolean { if (!header) return false; // "t=1786113454,v2=b4b2..." -> { t, v1?, v2? }. Unknown parts are ignored. const parts: Record<string, string> = {}; for (const piece of header.split(",")) { const i = piece.indexOf("="); if (i > 0) parts[piece.slice(0, i)] = piece.slice(i + 1); } // t is Unix time in SECONDS. const timestamp = Number(parts.t); if (!Number.isFinite(timestamp)) return false; const age = Math.floor(Date.now() / 1000) - timestamp; if (age > MAX_AGE_SECONDS || age < -MAX_FUTURE_SECONDS) return false; // Prefer v2 ("{t}.{body}"), fall back to v1 (body only) while you migrate. const received = parts.v2 ?? parts.v1; if (!received) return false; const signedPayload = parts.v2 ? ${parts.t}.${rawBody} : rawBody; const expected = crypto.createHmac("sha256", secret).update(signedPayload).digest("hex"); // timingSafeEqual throws if byte lengths differ, so check first. const a = Buffer.from(expected); const b = Buffer.from(received); if (a.length !== b.length) return false; return crypto.timingSafeEqual(a, b); } // Raw body on this route. Not express.json(). app.post("/webhooks/zavu", express.raw({ type: "application/json" }), (req, res) => { const rawBody = req.body.toString("utf8"); const header = req.headers["x-zavu-signature"] as string | undefined; if (!verifyZavuSignature(rawBody, header, SECRET)) { return res.status(401).send("Invalid signature"); } // Answer fast, then work. res.status(200).send("OK"); processEvent(JSON.parse(rawBody)).catch(console.error); });

    Three details that matter:

    • express.raw, not express.json(). The signature covers the exact bytes that were sent. Zavu's docs put it plainly: JSON.stringify(JSON.parse(x)) is not always x.
    • timingSafeEqual, not ===. Node documents it as a constant-time comparison that "does not leak timing information that would allow an attacker to guess one of the values". It also throws when the two buffers have different byte lengths, which is why the length check comes first.
    • Unknown parts are ignored. If a future scheme adds v3=..., this parser keeps working.

    The verifier above was run against signed requests: v1, v2, v1+v2, an unknown extra part, a tampered body, a stale t, a rewritten t, t in milliseconds, a non-ASCII header and an empty one all behave as described.

    Drop the v1 fallback when you are done

    The fallback to v1 exists so one verifier works during a migration. It also means a request carrying only a v1 part, with t rewritten, still passes. Once every webhook that points at this endpoint is on v2, remove the fallback and require v2. That is the moment the replay window is fully closed.

    What are the common mistakes?

    Zavu's troubleshooting section lists the usual causes of "every delivery returns 401", in order of likelihood. Here they are, with a few more:

    MistakeWhat happensFix
    Hashing the wrong payloadEvery delivery failsCheck signatureVersion on the sender. On v1, hash the body. On v2, hash {t}.{body}
    A body parser ran firstEvery delivery fails, or only some (key order, escaping)Verify the raw bytes, then parse
    Wrong secretEvery delivery failsThe secret is per sender. Regenerating it invalidates the old one immediately, with no overlap
    t treated as millisecondsEvery delivery looks ancient, or from the futuret is in seconds. The payload's own timestamp field is in milliseconds; do not mix them
    Using === / ==Works, but leaks timingcrypto.timingSafeEqual
    Checking t on a body-only signatureFeels safe, is notMove to v2
    Returning 200 before verifyingLooks healthy from outside, verifies nothingVerify first, then acknowledge
    Turning verification off to test locallyShips to production by accidentSend yourself a signed request (below)

    The most common version of the first mistake is mixing the two schemes: hashing {t}.{body} and comparing it to v1. v1 covers the body alone, so that receiver rejects every delivery. Either hash the body for v1, or move the sender to v2, where {t}.{body} is correct.

    Why do you still need idempotency if you check the timestamp?

    Because not every repeat is an attack.

    Your endpoint must answer with a 2xx within 30 seconds. If it returns an error or times out, Zavu tries again with backoff:

    AttemptWhen
    1st (original)Immediately
    2nd1 minute after the 1st fails
    3rd5 minutes after the 2nd fails
    4th15 minutes after the 3rd fails
    5th1 hour after the 4th fails

    After five failed attempts the delivery is marked as failed, and you can see it, with the reason, in the dashboard.

    Every attempt is signed again when it is sent. So a legitimate retry is a real delivery with a fresh timestamp and a valid signature. Delivery is at-least-once: you will see the same event twice, and the five-minute window will not catch it, because it is not supposed to.

    Two checks, two jobs:

    • The timestamp stops someone from replaying an old request.
    • Idempotency stops your own system from processing a real event twice.
    TypeScript
    // Store event.id and ignore what you have already processed. // A Set is fine for a demo; in production use your database (unique index on the event id). const seen = new Set<string>(); async function processEvent(event: { id: string; type: string; data: unknown }) { if (seen.has(event.id)) return; seen.add(event.id); // ...handle message.inbound, message.delivered, message.failed... }

    Meta works the same way on its side. Failed WhatsApp webhook deliveries are retried "a few more times with decreasing frequency over the next 7 days", and Meta's docs say your server "should handle deduplication". Different providers, same lesson.

    Answer fast. Verify first. Deduplicate always.

    How do you test it without turning it off?

    Sign a request yourself. This is the example from Zavu's docs:

    terminal
    BODY='{"id":"evt_test","type":"message.inbound","data":{}}' SIG=$(node -e " const c=require('crypto'); const t=Math.floor(Date.now()/1000); const b=process.argv[1]; console.log('t='+t+',v2='+c.createHmac('sha256','$ZAVU_WEBHOOK_SECRET').update(t+'.'+b).digest('hex')); " "$BODY") curl -i -X POST localhost:3000/webhooks/zavu \ -H "X-Zavu-Signature: $SIG" \ -H "Content-Type: application/json" \ -d "$BODY"

    You should get a 200. Then change one character of the body and expect a 401.

    A receiver that returns 200 both times is not verifying anything.

    Checklist

    • The route reads the raw body; no JSON parser runs before verification.
    • The header is parsed by name, and unknown parts are ignored.
    • t is read as seconds and checked: at most 300 s old, at most 60 s in the future.
    • The signed string is {t}.{body} for v2, the body for v1.
    • Comparison uses crypto.timingSafeEqual, after a length check.
    • Verification happens before the 200.
    • event.id is stored, and duplicates are skipped.
    • Once every webhook pointing at the endpoint is on v2, the v1 fallback is removed.

    What this means in Zavu

    Every Zavu webhook is signed with HMAC-SHA256. New webhooks use v2, so the timestamp is signed and the replay window works. The question is what your existing endpoints are on.

    The project webhook (POST /v1/invitations/webhook, for invitation, broadcast, email domain and sandbox events) follows the same rules: a new one is signed with v2, and one configured earlier moves with the same three steps, using signatureVersion on PATCH /v1/invitations/webhook. GET /v1/invitations/webhook tells you where it is.

    Check your scheme

    terminal
    curl https://api.zavu.dev/v1/senders/$SENDER_ID \ -H "Authorization: Bearer $ZAVUDEV_API_KEY"

    The response includes the webhook and its scheme (excerpt):

    JSON
    { "webhook": { "url": "https://api.example.com/webhooks/zavu", "active": true, "signatureVersion": "v1" } }

    The dashboard shows every webhook's scheme, and its next step, under Webhooks.

    Move from v1 to v2 without downtime

    It is three steps on purpose.

    1. Turn on both.

    terminal
    curl -X PATCH https://api.zavu.dev/v1/senders/$SENDER_ID \ -H "Authorization: Bearer $ZAVUDEV_API_KEY" \ -H "Content-Type: application/json" \ -d '{"webhookSignatureVersion": "v1+v2"}'

    The header now carries both, sharing one timestamp: t=...,v1=...,v2=.... Your current receiver keeps reading v1 and notices nothing.

    2. Deploy the verifier above, which prefers v2 and falls back to v1, and watch real deliveries land in your own logs. A test request is not enough: a receiver that answers 200 before verifying looks exactly like a working one from Zavu's side.

    3. Turn v1 off.

    terminal
    curl -X PATCH https://api.zavu.dev/v1/senders/$SENDER_ID \ -H "Authorization: Bearer $ZAVUDEV_API_KEY" \ -H "Content-Type: application/json" \ -d '{"webhookSignatureVersion": "v2"}'

    Jumping from v1 straight to v2 is rejected with a 400, and so is jumping from v2 straight back to v1: a receiver that verifies only v2 would reject every delivery. Rolling back means setting v1+v2 again, and both signatures come back on the next delivery.

    If one endpoint serves several senders, move them one at a time; the tolerant verifier accepts both schemes in the meantime. And when you create a new sender that points at an endpoint still verifying v1, create it with "webhookSignatureVersion": "v1+v2". Otherwise it defaults to v2, and that endpoint will reject its deliveries.

    Why sign the clock? Because a valid signature on a stale request is still a stale request.

    Your URL will stay public. That is fine. Public is not the problem. Trusting a request you cannot prove is.

    Sign the body. Sign the clock. Then trust it.

    Sources

    Checked on November 25, 2026.

    Frequently asked questions

    What is webhook signature verification?
    Webhook signature verification is the check a server runs to confirm a webhook came from the provider and was not modified. The provider signs each request with a shared secret, usually with HMAC-SHA256, and the receiver recomputes the signature over the raw body and compares the two in constant time.
    How do I verify an HMAC-SHA256 webhook signature?
    Read the raw request body, rebuild the exact string the provider signed (for a Zavu v2 webhook, {t}.{body}), compute HMAC-SHA256 with your webhook secret as hex, and compare it to the header value with a constant-time function such as crypto.timingSafeEqual in Node. Reject the request on any mismatch.
    Why does my webhook signature never match?
    Usually one of four causes: you hash a parsed and re-serialized body instead of the raw bytes, you hash the wrong payload for your scheme (body versus {t}.{body}), you use the wrong secret (Zavu secrets are per sender), or you read the timestamp as milliseconds when it is in seconds.
    What is a webhook replay attack?
    A webhook replay attack is when someone resends a valid request they captured earlier. If only the body is signed, the old signature stays valid forever. Signing the timestamp together with the body, and rejecting timestamps older than a few minutes, makes a captured request useless after that window.
    Why not compare webhook signatures with === or ==?
    A normal string comparison can return as soon as one character differs, so response time can leak how much of a guessed signature was correct. A constant-time function such as Node's crypto.timingSafeEqual takes the same time whatever the input, and is the documented way to check an HMAC.
    How old can a Zavu webhook be before I reject it?
    Zavu's documentation rejects a delivery whose t is more than 300 seconds (five minutes) old, or more than 60 seconds in the future. The t value is a Unix timestamp in seconds, and you recompute the signature with the t from the header, not with your own clock.
    Does checking the timestamp replace idempotency?
    No. Zavu retries a failed delivery, and every retry is signed again with a fresh timestamp, so it passes the freshness check. Delivery is at-least-once. Store each event's id and skip events you have already processed, ideally with a unique index in your database.
    Do I have to migrate my Zavu webhook from v1 to v2 signatures?
    No. There is no deadline, and v1 webhooks keep working. New webhooks are created on v2, which signs the timestamp and makes the replay window effective. Moving an existing one takes three steps: switch to v1+v2, deploy a verifier that prefers v2, then switch to v2.

    Need help? Contact us or join our Discord community for support.

    Get started

    Ready to get started?

    Start building for free, or schedule a call to discuss your specific use case.

    Webhook Signature Verification with HMAC-SHA256 (2026) | Zavu Blog