Webhooks

Verify Wybox webhooks with X-Wybox-Timestamp and X-Wybox-Signature. The signature is HMAC-SHA256. Reject timestamps older than five minutes.

A webhook delivery is an HTTP POST of the alert body. Two headers travel with it:

  • X-Wybox-Timestamp is unix time in seconds. Reject timestamps older than 5 minutes.
  • X-Wybox-Signature is the string v1= followed by HMAC-SHA256 of timestamp + "." + raw body, using the tenant webhook secret.

Compare the signature with a constant-time check, over the raw body, before you parse JSON.

import { createHmac, timingSafeEqual } from "node:crypto";

export function verifyWyboxWebhook(rawBody: string, headers: Headers, secret: string) {
  const timestamp = headers.get("x-wybox-timestamp") ?? "";
  const signature = headers.get("x-wybox-signature") ?? "";
  const age = Math.abs(Date.now() / 1000 - Number(timestamp));
  if (!Number.isFinite(age) || age > 300) return false;
  const expected = "v1=" + createHmac("sha256", secret).update(`${timestamp}.${rawBody}`).digest("hex");
  const left = Buffer.from(expected);
  const right = Buffer.from(signature);
  return left.length === right.length && timingSafeEqual(left, right);
}

The sample above is example code for the header names in the OpenAPI file. It is not a live event.