Skip to content

verifySignature

verifySignature(rawBody, signatureHeader, appSecret): boolean

Defined in: src/resources/webhooks.ts:132

Verifies the X-Hub-Signature-256 header against the HMAC-SHA256 of the raw request body using the App Secret. Uses a constant-time comparison and never throws on malformed input.

SECURITY: rawBody MUST be the raw, unparsed request bytes exactly as received. Passing re-serialized JSON changes the bytes and makes a legitimate signature fail. The app secret and signature are never logged or embedded in errors.

WebhookRawBody

The raw request body: a string, Uint8Array (including Buffer) or ArrayBuffer. Any other type yields false.

string | undefined

The X-Hub-Signature-256 header value, if present.

string | readonly string[]

The App Secret used to compute the expected signature, or an array of secrets to accept during rotation. Every secret is checked (there is no early exit); empty or non-string entries are ignored.

boolean

true only when the signature is present, well-formed, and matches at least one secret. Returns false when no usable secret is given, so an empty key can never validate a signature.

Independent open-source project. Not affiliated with, endorsed by or sponsored by Meta or WhatsApp. Released under the MIT licence. Source on GitHub.