I have an Express.js Webhook consumer but it is failing to verify if the body_html of the product has unicode characters.
The below will verify:
“body_html”:“Intensiv, komplex, raffiniert und ausgewogen”
But this will fail to verify:
“body_html”:“\u003cp\u003e\u003cstrong\u003eIntensiv, komplex, raffiniert und ausgewogen \u003c/strong\u003e\u003c/p\u003e\n\u003cp\u003e”
Below are the fundamental parts of the Webhook handler:
function validateShopifySignature() {
return async (req, res, next) => {
try {
const rawBody = req.rawBody
if (typeof rawBody == 'undefined') {
throw new Error(
'validateShopifySignature: req.rawBody is undefined. Please make sure the raw request body is available as req.rawBody.'
)
}
const hmac = req.headers['x-shopify-hmac-sha256']
const hash = crypto.createHmac('sha256', process.env.SHOPIFY_WEBHOOK_SIGNATURE).update(rawBody).digest('base64')
const signatureOk = crypto.timingSafeEqual(Buffer.from(hash), Buffer.from(hmac))
if (!signatureOk) {
res.status(403).send('Unauthorized')
return
}
next()
} catch (err) {
next(err)
}
}
}
app.use(
express.json({
limit: '50mb',
verify: (req, res, buf) => {
req.rawBody = buf
},
})
)
app.post('/webhook/product/update', validateShopifySignature(), (req, res, next) => {
res.status(200).send('OK')
})
How can I get this to work even if body_html has unicode characters?