Skip to content
Support

Verify a webhook signature

Owner, AdminLast checked 24 November 20262 min readArticle ID: developers-webhook-signatures
On this page

Check the X-Skeduler-Signature-V2 header on every delivery with your signing secret, with examples for Node and PHP.

Anyone can post to your URL. Only Skeduler can sign with your secret, so check the signature on every delivery before you trust it.

Who can do this: Owners and Admins with the Manage Developer Tools permission.

The steps

  1. Read the raw request body, exactly as received. Don't parse it and turn it back into JSON first: the signature covers the exact bytes.

  2. Split the X-Skeduler-Signature-V2 header (t=<unix seconds>,v1=<hex>) into t and v1.

  3. Reject the delivery if t is more than 5 minutes from your clock. This stops an old delivery being replayed.

  4. Work out HMAC-SHA256(secret, "<t>.<raw body>") as lowercase hex, and compare it to v1 with a constant-time comparison.

If they match, the delivery is genuine: handle it and answer 2xx. If not, reject it. The examples below answer 400.

Node (Express)

import crypto from "node:crypto";
import express from "express";

const SECRET = process.env.SKEDULER_SIGNING_SECRET;
const app = express();

// express.raw keeps the body as the exact bytes; don't use express.json() here.
app.post("/skeduler/webhook", express.raw({ type: "application/json" }), (req, res) => {
  const header = req.get("X-Skeduler-Signature-V2") ?? "";
  const parts = Object.fromEntries(header.split(",").map((p) => p.split("=", 2)));
  const t = Number(parts.t);

  if (!parts.v1 || !Number.isInteger(t) || Math.abs(Date.now() / 1000 - t) > 300) {
    return res.sendStatus(400);
  }

  const expected = crypto.createHmac("sha256", SECRET).update(`${t}.`).update(req.body).digest("hex");
  const given = Buffer.from(parts.v1, "hex");
  const wanted = Buffer.from(expected, "hex");

  if (given.length !== wanted.length || !crypto.timingSafeEqual(given, wanted)) {
    return res.sendStatus(400);
  }

  const delivery = JSON.parse(req.body.toString("utf8"));
  // Handle delivery.event; use delivery.delivery_id to ignore a repeat.
  res.sendStatus(200);
});

PHP

<?php
$secret = getenv('SKEDULER_SIGNING_SECRET');
$raw = file_get_contents('php://input');               // the exact bytes
$header = $_SERVER['HTTP_X_SKEDULER_SIGNATURE_V2'] ?? '';

parse_str(str_replace(',', '&', $header), $parts);     // t=…,v1=… -> ['t' => …, 'v1' => …]
$t = $parts['t'] ?? '';
$given = $parts['v1'] ?? '';

if (! ctype_digit((string) $t) || $given === '' || abs(time() - (int) $t) > 300) {
    http_response_code(400);
    exit;
}

$expected = hash_hmac('sha256', $t.'.'.$raw, $secret);

if (! hash_equals($expected, $given)) {
    http_response_code(400);
    exit;
}

$delivery = json_decode($raw, true);
// Handle $delivery['event']; use $delivery['delivery_id'] to ignore a repeat.
http_response_code(200);

An older header, X-Skeduler-Signature (sha256=<hex HMAC of the raw body>), is still sent but has no timestamp. Use X-Skeduler-Signature-V2.

In this section