HMAC signatures
How to confirm the request really came from DroidSender and not from someone else.
Every request carries the X-DroidSender-Signature header, holding an HMAC-SHA256 of the request body computed with your webhook's secret. Verifying the signature is what stops anyone who discovers your URL from sending you fake events.
javascript
const crypto = require("crypto");
function signatureIsValid(rawBody, signature, secret) {
const expected = crypto
.createHmac("sha256", secret)
.update(rawBody)
.digest("hex");
// constant-time comparison: a plain === lets the secret be measured
return crypto.timingSafeEqual(
Buffer.from(expected),
Buffer.from(signature),
);
}Use the raw body
The signature is computed over the JSON exactly as it arrived. If you verify it after parsing it into an object and serialising it again, the whitespace changes and the signature never matches.