Log in

Verify SMS webhook HMAC-SHA256 signatures

How to confirm the request really came from DroidSender and not from someone else.

Last updated

HeaderWhat it holds
X-DroidSender-Eventthe event name, the same one in the body
X-DroidSender-Deliveryidentifies one delivery attempt; to deduplicate, use event plus data.id (plus data.status for sent, delivered and failed)
X-DroidSender-Signaturethe signature, described below
User-AgentDroidSender-Webhooks/2.0

Every request carries the X-DroidSender-Signature header in the form t=<unix seconds>,v1=<hex>, where v1 is the HMAC-SHA256 of "<t>.<raw body>" using your webhook's secret.

const crypto = require("crypto");

function signatureIsValid(rawBody, header, secret) {
  const match = /^t=(\d+),v1=([0-9a-f]{64})$/.exec(header ?? "");
  if (!match) return false;

  const [, t, received] = match;

  // the timestamp is inside what is signed: an intercepted delivery
  // cannot be replayed tomorrow, and t cannot be rewritten without the secret
  const age = Math.abs(Math.floor(Date.now() / 1000) - Number(t));
  if (age > 300) return false;

  const expected = crypto
    .createHmac("sha256", secret)
    .update(`${t}.${rawBody}`)
    .digest("hex");

  // constant-time comparison: a plain === lets the secret be measured
  return crypto.timingSafeEqual(
    Buffer.from(expected, "hex"),
    Buffer.from(received, "hex"),
  );
}

Use DroidSender from ChatGPT, Claude, Gemini or Grok. Your assistant can prepare your list, send and pause campaigns, check your phones and fix errors for you, on every plan.

See how it works

Your cookie preferences

We use essential cookies to run this site. With your consent, we also use analytics and advertising cookies to understand visits and measure our ads. You can change your choice at any time in Cookie settings. Cookie policy