Complete guide to webhooks, debugging, and real-time event monitoring with HookMetry
Signature validation ensures that webhooks are authentic and haven't been tampered with. It prevents unauthorized parties from sending fake webhooks to your endpoint.
Both you and the webhook provider share a secret key (never transmitted with webhooks)
Provider creates an HMAC hash of the payload using the secret key (typically SHA-256)
The signature is included in a header (e.g., X-Webhook-Signature)
Compute the same HMAC with your secret and compare - if they match, the webhook is authentic
const crypto = require('crypto');
function verifyWebhookSignature(payload, signature, secret) {
// Compute HMAC hash of the payload
const computedSignature = crypto
.createHmac('sha256', secret)
.update(JSON.stringify(payload))
.digest('hex');
// Compare signatures (timing-safe comparison)
return crypto.timingSafeEqual(
Buffer.from(signature),
Buffer.from(computedSignature)
);
}
// Usage
const isValid = verifyWebhookSignature(
req.body,
req.headers['x-webhook-signature'],
process.env.WEBHOOK_SECRET
);
if (!isValid) {
return res.status(401).json({ error: 'Invalid signature' });
}HookMetry Advantage:
HookMetry automatically validates signatures for Stripe, GitHub, and custom HMAC webhooks. You can see validation results in real-time, making debugging authentication issues effortless.