Cluster 14 · DevTools Provider · sha256=<hex>

GitHub X-Hub-Signature-256 Verification, Delivery GUID Idempotency & Retry Pattern

Validate GitHub Apps & repository webhooks with `X-Hub-Signature-256`, deduplicate using `X-GitHub-Delivery`, and obey GitHub's 10-second response SLA and rate-limit headers.

100% Browser-Side · WebCrypto crypto.subtle · Strict CSP

1. Webhook Signature & Replay-Window Inputs

crypto.subtle HMAC-SHA256
Paste an incoming signature header to run constant-time verification.
Replay-Window & Clock-Skew Gate
18s age vs 300s max
PASS: WITHIN REPLAY WINDOW
Event age 18s is within <=300s tolerance window (282s remaining). Pair with Idempotency/Delivery ID cache. (135 UTF-8 bytes · GitHub signs raw UTF-8 body bytes with `sha256=<hex>`; deduplicate deliveries via `X-GitHub-Delivery` UUID.)
Computed HTTP Signature Header
X-Hub-Signature-256: sha256=f82046aaebadf6e0f1a4de884c7fc2a2861bdfd012f51a85657559433ebbee45
HMAC-SHA256 Hex
f82046aaebadf6e0f1a4de884c7fc2a2861bdfd012f51a85657559433ebbee45
HMAC-SHA256 Base64
+CBGquut9uDxpN6ITH/CooYb39AS9RqFZXVZQz677kU=
Drop-In WebCrypto Verifier + Replay Guard (verifyWebhook.ts)
// Strict WebCrypto Webhook Verifier + Replay Guard (Cloudflare Workers / Node 20+)
const REPLAY_TOLERANCE_SEC = 300;

function timingSafeEqual(a: Uint8Array, b: Uint8Array): boolean {
  if (a.length !== b.length) return false;
  let diff = 0;
  for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i];
  return diff === 0;
}

export async function verifyWebhookRequest(request: Request, secret: string): Promise<{ ok: boolean; reason: string; rawBody: string }> {
  const rawBody = await request.text();
  const sigHeader = request.headers.get("x-hub-signature-256") || "";
  const signedInput = rawBody;
  const providedSig = sigHeader.replace(/^sha256=/i, "").toLowerCase();
  const enc = new TextEncoder();
  const key = await crypto.subtle.importKey("raw", enc.encode(secret), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
  const mac = new Uint8Array(await crypto.subtle.sign("HMAC", key, enc.encode(signedInput)));
  const expectedHex = [...mac].map((b) => b.toString(16).padStart(2, "0")).join("");
  const ok = timingSafeEqual(enc.encode(providedSig), enc.encode(expectedHex));
  return { ok, reason: ok ? "verified" : "invalid_signature", rawBody };
}
WebhookSLA Guard · Live Check $29 WebhookSLA Guard Kit

Verify Live Webhook Replay Defense, 429 Retry-After & DLQ SLA Readiness

Run a live webhook endpoint & SLA audit on WebhookSLA Guard (webhook.runglab.dev), grab the turnkey $29 WebhookSLA Guard Kit (WebCrypto HMAC verifiers, replay-window store, RFC RateLimit-* middleware & DLQ runbooks) on Creem, or audit webhook OpenAPI specs on SpecDiff (spec.runglab.dev). Need a PayPal invoice? Email [email protected].

Webhook SLA, Signature & Retry Specification Matrix

Control / Header Production Baseline Reliability & Security Rationale
Signature Header X-Hub-Signature-256: sha256=<hex> Always prefer SHA-256 over legacy SHA-1 `X-Hub-Signature`
Delivery GUID X-GitHub-Delivery Unique UUID per webhook event; manual redeliveries reuse or issue new GUIDs
Response SLA < 10 seconds hard timeout GitHub terminates deliveries taking >= 10s; enqueue work immediately
Rate-Limit Compatibility HTTP 429 + Retry-After Advertise clean `RateLimit-*` and `Retry-After` headers under CI burst spikes

GitHub X-Hub-Signature-256 Constant-Time Verifier (Node.js)

github-webhook-verify.mjs
import crypto from "node:crypto";

export function verifyGitHubWebhook(rawBodyBuffer, headers, secret) {
  const sigHeader = String(headers["x-hub-signature-256"] || "");
  if (!sigHeader.startsWith("sha256=")) return false;
  const expected = "sha256=" + crypto.createHmac("sha256", secret).update(rawBodyBuffer).digest("hex");
  const a = Buffer.from(sigHeader, "utf8");
  const b = Buffer.from(expected, "utf8");
  return a.length === b.length && crypto.timingSafeEqual(a, b);
}

GitHub App RateLimit-* + 202 Accepted Queue Response

github-queue-response.http
HTTP/1.1 202 Accepted
Content-Type: application/json
X-GitHub-Delivery-Accepted: true
RateLimit-Policy: "webhook-ingest";q=200;w=60
RateLimit: "webhook-ingest";r=199;t=60

Implementation Steps & Key Insights

  1. Reject any request lacking `X-Hub-Signature-256` (`sha256=...`) with `401 Unauthorized` before parsing JSON.
  2. Compare HMAC-SHA256 over the exact raw request buffer using `crypto.timingSafeEqual` (checking equal buffer lengths first).
  3. Record `X-GitHub-Delivery` + `X-GitHub-Event` in a short-term deduplication cache (24h–72h TTL) to mitigate replay attacks.
  4. Respond `202 Accepted` within 10 seconds and process PR/push diffs in an asynchronous worker queue with DLQ visibility.
  • Unlike Stripe, GitHub does not include a timestamp in `X-Hub-Signature-256` — so caching `X-GitHub-Delivery` UUIDs is essential for replay resistance.
  • Monorepo pushes and Dependabot PR bursts easily trigger 50–200 webhooks within seconds; emit explicit `RateLimit-Policy` + `Retry-After` on 429s.
  • Always verify `crypto.timingSafeEqual` receives two equal-length buffers, otherwise Node.js throws a `RangeError`.

Common Production Pitfalls

  • Passing parsed `req.body` into HMAC instead of raw bytes — breaking UTF-8 emoji PR titles or commit messages.
  • Still trusting deprecated SHA-1 `X-Hub-Signature` instead of enforcing `X-Hub-Signature-256`.
  • Running `git clone` or LLM code review synchronously inside the webhook HTTP request, violating GitHub's 10-second timeout.
Ship Faster: Audit your live endpoint on webhook.runglab.dev or grab the $29 WebhookSLA Guard Kit.

More Enterprise Webhook SLA & Signature Guides

← Back to Webhook SLA Kit Hub · WebhookSLA Guard ($29 Kit) → · SpecDiff OpenAPI Audit → · Cluster 7B: CORS & HMAC → · Cluster 9: OpenAPI OWASP →

Frequently Asked Questions

Does GitHub automatically retry failed webhook deliveries?

GitHub Apps and Actions workflows surface failed deliveries in the UI/API for manual/API redelivery, while repository webhooks mark >10s timeouts as failed immediately.

Why does `crypto.timingSafeEqual` crash on malformed headers?

Node's `timingSafeEqual` throws if buffer byte lengths differ. Always assert `a.length === b.length` before calling it.

How does WebhookSLA Guard complement GitHub webhook development?

WebhookSLA Guard (`https://webhook.runglab.dev`) verifies your endpoint's live signature rejection, replay checks, and `Retry-After` SLA compliance.