Skip to content

verifySignatureAsync

verifySignatureAsync(rawBody, signatureHeader, secrets): Promise<boolean>

Defined in: src/resources/webhook-verify-web.ts:63

Verifies the X-Hub-Signature-256 header against the HMAC-SHA256 of the raw request body using Web Crypto. The comparison is constant time (crypto.subtle.verify). It never throws on malformed input.

The header must be sha256= followed by exactly 64 lowercase hex digits. Every secret is checked and the results are combined, so the time taken does not reveal which secret matched. Empty or non-string secrets are ignored.

SECURITY: rawBody MUST be the raw request bytes exactly as received.

string | ArrayBuffer | Uint8Array<ArrayBufferLike>

The raw body as a string, Uint8Array or ArrayBuffer.

string | undefined

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

string | readonly string[]

One App Secret, or several to accept during rotation.

Promise<boolean>

true only when the header is well formed and matches a secret.

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