Skip to content
PingbackDocs
DevelopersBuild

Verify signatures

Make sure a webhook really came from Pingback before acting on it.

Server-side

What's signed

The signature is a hex HMAC-SHA256 of timestamp + "." + delivery_id + "." + raw_body, using your endpoint's secret. Keep the original bytes: parsing and re-serialising JSON changes them.

Verify on your server

Node.js · no dependencies
import { createHmac, timingSafeEqual } from "node:crypto";

// Pass the untouched HTTP body as a Buffer, before JSON parsing.
export function verifySignature(rawBody, headers, secret) {
  const signature = headers.get("X-Pingback-Signature");
  const deliveryId = headers.get("X-Pingback-Delivery");
  if (!Buffer.isBuffer(rawBody) || !signature || !deliveryId || !secret) return false;
  const match = /^t=(\d+),v1=([a-f0-9]{64})$/.exec(signature);
  if (!match) return false;

  const [, timestamp, digest] = match;
  const age = Math.abs(Date.now() / 1000 - Number(timestamp));
  if (age > 300) return false;

  const expected = createHmac("sha256", secret)
    .update(timestamp + "." + deliveryId + ".")
    .update(rawBody)
    .digest();
  const received = Buffer.from(digest, "hex");
  return received.length === expected.length &&
    timingSafeEqual(received, expected);
}

Pass the raw body, the request headers and your whsec_ secret. Requests more than five minutes old are rejected, so keep your server clock in sync.

Handle retries

After verifying, save X-Pingback-Delivery with a unique constraint. If you've already processed it, return success without repeating the work. Don't rely on an in-memory list.