How to Correctly Verify Shopify Webhook Signatures in Node.js
Shopify webhook verification commonly fails due to two developer mistakes: using hex encoding instead of base64, and allowing a JSON body parser to process the request before the raw bytes are hashed. Unlike Stripe and GitHub, Shopify base64-encodes its HMAC-SHA256 signature in the X-Shopify-Hmac-Sha256 header, keyed with the app's client secret. Developers must capture the raw request body using Express's raw() middleware on the webhook route itself, compute the HMAC over those untouched bytes, and compare the result in constant time using crypto.timingSafeEqual to prevent timing attacks. Parsing the JSON body before verification alters whitespace and key order, causing the signature check to fail even when the secret is correct. Shopify also expects a fast 200 response on success, so returning a 401 on HMAC mismatch and keeping the handler lightweight is recommended.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in