I get webhooks from a woocommerce site in a nodejs / express application. I am trying to verify the webhook signature to verify the authenticity, but the hash I compute never matches the signature that Woocommerce reports in the hook signature header.
Here is the code I use for authentication:
function verifySignature(signature, payload, key){ var computedSignature = crypto.createHmac("sha256", key).update(payload).digest('base64'); debug('computed signature: %s', computedSignature); return computedSignature === signature; }
This function is called with the following parameters:
var signature = req.headers['x-wc-webhook-signature']; verifySignature(signature, JSON.stringify(req.body), config.wooCommence.accounts.api[config.env].webhookSecret)
The webhook header headers report the signature as BewIV/zZMbmuJkHaUwaQxjX8yR6jRktPZQN9j2+67Oo= . However, the result of the above operation is S34YqftH1R8F4uH4Ya2BSM1rn0H9NiqEA2Nr7W1CWZs=
I manually configured the secret in webhook, and, as you see in the code above, the same secret is also hardcoded in the express application. Therefore, either I take the wrong payload to calculate the signature, or there is something else suspicious that prevents me from checking this signature.
Would thank all the pointers that will help me solve this problem.
source share