WhatsApp and Meta webhooks: verify token and X-Hub-Signature-256 failures
Your callback URL will not save in the Meta App Dashboard, or your endpoint rejects a
POST carrying X-Hub-Signature-256. Start by separating the two checks:
| Request | What to check | Successful response |
|---|---|---|
Verification GET |
hub.mode, hub.verify_token, hub.challenge |
200 with the challenge value |
Event POST |
HMAC-SHA256 of the body with the App Secret | 200 after durable acceptance |
Meta documents the verification parameters and the payload signature separately. Passing the verification request does not test the POST verifier in the sample below.
1. The verify token does not match
Section titled “1. The verify token does not match”The verify token is a string you choose and store on your server. Use that same string in the
App Dashboard’s Verify token field. Meta sends it as hub.verify_token on a verification
GET. Compare it with your configured value, and check that hub.mode is subscribe.
The sample uses 403 for a wrong token or mode and does not return the challenge on failure.
It compares token hashes in constant time. An empty configured token is rejected.
2. The challenge response has the wrong shape
Section titled “2. The challenge response has the wrong shape”Meta’s WhatsApp endpoint documentation requires status 200 and the hub.challenge value
for a valid verification request. Return the challenge as plain text. Do not wrap it in a JSON
object or add quotes. For the test challenge 1158201444, the sample returns exactly those
bytes. A JSON object or quoted string would have different bytes.
Allow GET on the same callback path as POST. A POST-only route cannot handle Meta’s
verification GET request. Check the route and any proxy method restrictions.
3. HTTPS or the certificate blocks verification
Section titled “3. HTTPS or the certificate blocks verification”Meta requires HTTPS and a valid TLS or SSL certificate. Self-signed certificates are not supported. Check the public callback URL from outside your private network. Fix the certificate chain and routing before debugging the token or signature.
4. The signature key or prefix is wrong
Section titled “4. The signature key or prefix is wrong”For event notifications, Meta puts the signature in X-Hub-Signature-256, prefixed with
sha256=. WhatsApp documents HMAC-SHA256 with the POST body as the message and the App Secret
as the secret key. Configure the App Secret for the app receiving the event; do not substitute
an access token or the verification string.
The samples reject missing headers, malformed hex, wrong secrets and empty secrets. They decode the digest after the prefix and compare bytes in constant time. Header lookup in the Express route also accepts a lowercase header name, as the handler vector proves.
Meta documents the lowercase sha256= prefix but does not specify hex letter case. These
samples accept uppercase and mixed-case hex digits, reject an uppercase prefix, and reject
non-hex or oversized digests. Shared vectors prove these choices in all three languages.
5. Parsing changed the signed bytes
Section titled “5. Parsing changed the signed bytes”Verify the original request bytes before parsing JSON. The local extra-unicode vector contains
both an escaped and an unescaped non-ASCII character. Its original body passes all three
verifiers. Parsing and re-serializing that body replaces the escape with a literal character;
the original signature then fails. This reproduction shows a byte change, not that Unicode is
a universal cause of failures.
For one request, compare body length and SHA-256 before and after a suspected proxy or parser. Different measurements for the same request identify a body change. Avoid logging payloads or secrets. Do not compare separate deliveries or a real delivery with a synthetic test.
Express: both routes and durable acceptance
Section titled “Express: both routes and durable acceptance”Call createMetaApp with your configured verify token, App Secret and a durable enqueue
implementation. It starts no server by itself. Register the raw-body route before global JSON
middleware. The sample rejects compressed requests instead of decompressing bytes before verification.
The 1 MiB parser limit is this example’s local policy; choose your own accepted size.
The enqueue promise must resolve only after the queue durably stores the body. Run processing
in a separate worker. The adapter uses a fake queue to prove that successful acceptance stores
one item and queue failure returns 500, with no processing. It does not prove a production
queue’s durability.
import crypto from "node:crypto";import express from "express";
function metaSignature(rawBody, header, appSecret) { if (typeof header !== "string" || header.length === 0) return "missing"; if (typeof appSecret !== "string" || appSecret.length === 0) return "invalid"; if (!Buffer.isBuffer(rawBody) || !/^sha256=[0-9a-fA-F]{64}$/.test(header)) return "invalid"; const expected = crypto.createHmac("sha256", appSecret).update(rawBody).digest(); const given = Buffer.from(header.slice(7), "hex"); return crypto.timingSafeEqual(given, expected) ? "valid" : "invalid";}
function sameToken(given, configured) { if (typeof given !== "string" || typeof configured !== "string" || !configured) return false; const a = crypto.createHash("sha256").update(given).digest(); const b = crypto.createHash("sha256").update(configured).digest(); return crypto.timingSafeEqual(a, b);}
// enqueue must resolve only after durable storage; a separate worker processes it.function createMetaApp({ verifyToken, appSecret, enqueue }) { const app = express(); app.set("query parser", "simple"); app.get("/webhooks/meta", (req, res) => { const challenge = req.query["hub.challenge"]; if (req.query["hub.mode"] !== "subscribe" || !sameToken(req.query["hub.verify_token"], verifyToken) || typeof challenge !== "string" || challenge.length === 0) { return res.status(403).type("text/plain").send("Forbidden"); } return res.status(200).type("text/plain").send(challenge); }); // Register this route before any global JSON parser. 1 MiB is a local policy, not a Meta limit. app.post("/webhooks/meta", express.raw({ type: "application/json", limit: "1mb", inflate: false }), async (req, res) => { if (metaSignature(req.body, req.get("X-Hub-Signature-256"), appSecret) !== "valid") { return res.status(401).type("text/plain").send("Invalid signature"); } try { await enqueue(req.body); } catch { return res.status(500).type("text/plain").send("Queue unavailable"); } return res.status(200).type("text/plain").send("OK"); }); return app;}Python: signature verification
Section titled “Python: signature verification”Pass the original body as bytes, the signature header and your App Secret to this function.
It returns missing, invalid or valid; it does not accept or process an event.
import hashlibimport hmacimport re
def meta_signature(raw_body: bytes, header: str | None, app_secret: str) -> str: if header is None or header == "": return "missing" if not app_secret or re.fullmatch(r"sha256=[0-9a-fA-F]{64}", header) is None: return "invalid" expected = hmac.new(app_secret.encode("utf-8"), raw_body, hashlib.sha256).digest() given = bytes.fromhex(header[7:]) return "valid" if hmac.compare_digest(given, expected) else "invalid"Go: signature verification
Section titled “Go: signature verification”Pass the original body bytes and the header value to this verifier.
import ( "crypto/hmac" "crypto/sha256" "encoding/hex" "strings")
func metaSignature(rawBody []byte, header, appSecret string) string { if header == "" { return "missing" } if appSecret == "" || !strings.HasPrefix(header, "sha256=") || len(header) != 71 { return "invalid" } given, err := hex.DecodeString(header[7:]) if err != nil { return "invalid" } mac := hmac.New(sha256.New, []byte(appSecret)) mac.Write(rawBody) if hmac.Equal(given, mac.Sum(nil)) { return "valid" } return "invalid"}Responses and retries: keep the products separate
Section titled “Responses and retries: keep the products separate”The Graph API getting-started page says to answer event notifications with 200 OK. Its
Frequency section describes retries with decreasing frequency over the next 36 hours,
and explicitly says Messenger notification frequency differs. Do not apply that window to
Messenger without checking its product documentation.
The WhatsApp overview’s Webhook delivery failure section gives up to 7 days when the
response is not 200 or delivery fails for another reason. It says retries go to all apps
subscribed to the relevant Messaging account fields and can produce duplicates. The WhatsApp
endpoint page’s Batching section also gives 7 days.
Verify first, durably store or enqueue second, then answer 200. Return 500 when durable
acceptance fails, as the handler test demonstrates. Process asynchronously after acceptance.
A failed delivery may already have been accepted if its response was lost. Deduplicate at the
worker before side effects, including during redelivery or backfill. The signature check alone
does not prevent repeat processing.
Checklist
Section titled “Checklist”- The public callback accepts both GET and POST over HTTPS with a valid certificate.
- The configured verification string matches the dashboard value, and the mode is
subscribe. - Successful verification returns
200and exactly the challenge, with no JSON wrapper. - The POST verifier uses the App Secret, original body bytes and the
sha256=prefix. - The handler waits for durable acceptance before returning
200and fails with500when it cannot enqueue. - The worker deduplicates events before processing, and retry planning uses the correct product’s documentation.
Sources
Section titled “Sources”Checked on 2026-10-11.
- Meta: Graph API webhooks getting started: “Create an endpoint”, “Verification Requests”, “Validating Verification Requests”, “Validating Payloads”, “Responding to Event Notifications” and “Frequency”.
- Meta: WhatsApp webhooks overview: “Webhook delivery failure”.
- Meta: Create a WhatsApp webhook endpoint: “TLS/SSL”, “GET requests”, “Validation”, “Response”, “POST requests”, “Request parameters”, and “Batching”.
The vectors are synthetic, generated with node:crypto from the documented HMAC-SHA256
algorithm. They are not a Meta worked example and use no official verification library.