Compute the signature with your endpoint secret, compare in constant time, then trust the body. The same secret survives rotation: when you rotate, the previous secret keeps validating for twenty-four hours so you can deploy at your own pace.
// Verify a webhook signature (Node.js)
import crypto from 'crypto';
function verifyWebhook(payload, signatureHeader, secret) {
const expected = crypto
.createHmac('sha256', secret)
.update(payload)
.digest('hex');
return crypto.timingSafeEqual(
Buffer.from(expected),
Buffer.from(signatureHeader),
);
}