Dev.to Security 🔐 Cybersecurity 👁 0 📖 5 min read

Rotating Webhook Signing Secrets Without Downtime

Rotating a webhook signing secret often comes with a few deliveries that fail verification. It doesn't have to: we show how signing with both secrets during an overlap window gets you to zero failed deliveries, and what

Rotating a webhook signing secret often comes with a few deliveries that fail verification. It doesn't have to: we show how signing with both secrets during an overlap window gets you to zero failed deliveries, and what to do with senders that only sign once.

You can rotate a webhook signing secret without a single failed delivery. For a limited window, the sender signs every webhook with both the old and the new secret and sends both signatures; the receiver accepts the request if either one matches. When the window closes, the sender stops using the old secret and the receiver forgets it. This post walks through both sides, covers senders that only send one signature, and ends with a runbook for leaked secrets.

How providers handle rotation

Checked against official documentation on 2026-09-27.

Multiple signatures Overlap window Receiver's job
Standard Webhooks Space-separated in webhook-signature Not fixed by the spec Accept if any one matches
Stripe Several v1= entries in Stripe-Signature Expire immediately, or keep the old secret up to 24 hours Accept if any one matches
Svix Same as Standard Webhooks 24 hours Accept if any one matches
GitHub One (X-Hub-Signature-256) No overlap mechanism documented Hold both secrets and try each

Sources: Standard Webhooks spec, Stripe webhooks (rolling secrets), Svix update, December 2021, Svix on zero-downtime rotation, GitHub: validating deliveries

In Stripe, you roll a secret from the endpoint's menu in the Webhooks tab. You can expire the current secret right away or extend it by up to 24 hours; while both are active, Stripe generates one signature per secret. Svix describes signing with both the new and existing secret for 24 hours so delivery isn't interrupted.

Sender side

  1. Generate a new secret. In the Standard Webhooks format that's 24-64 random bytes, base64-encoded, prefixed with whsec_.
  2. Start signing with both. Store the old secret with an expiry, for example 24 hours from now.
  3. Give the receiver the new secret through whatever channel you already use: the dashboard, an API response, a customer portal.
  4. Stop signing with the old secret at expiry, and delete it from storage.

Storing secrets as a newest-first list of { secret, until } keeps the logic small:

import { createHmac, randomBytes } from 'node:crypto';

type SecretEntry = { secret: string; until: number | null }; // null = current secret

export function newSecret(): string {
  return `whsec_${randomBytes(24).toString('base64')}`;
}

export function rotate(list: SecretEntry[], now: number, overlapMs = 24 * 3600_000): SecretEntry[] {
  const active = list.filter((e) => e.until === null || e.until > now);
  return [{ secret: newSecret(), until: null }, ...active.map((e) => ({ secret: e.secret, until: now + overlapMs }))];
}

export function sign(id: string, ts: string, body: string, list: SecretEntry[], now: number): string {
  return list
    .filter((e) => e.until === null || e.until > now)
    .map((e) => {
      const key = Buffer.from(e.secret.replace(/^whsec_/, ''), 'base64');
      return `v1,${createHmac('sha256', key).update(`${id}.${ts}.${body}`).digest('base64')}`;
    })
    .join(' '); // space-separated in webhook-signature
}

Pick the window based on how long receivers need. If the receiver is another team in your company, a few hours may do. If it's your customers, someone has to notice and change a setting, so default to 24 hours and tell them ahead of time.

Receiver side (multiple signatures)

With Standard Webhooks or Stripe, where both signatures arrive together:

  1. Confirm your verifier handles multiple signatures: split webhook-signature on spaces and pass if any entry matches. The official standardwebhooks library already does this.
  2. The sender rotates. Requests now carry old and new signatures. You still verify with the old secret, which matches.
  3. Swap in the new secret everywhere your receiver runs. The new signature matches.
  4. The window ends. The sender drops the old signature; you're already on the new secret.

Step 3 has to happen inside the window. Swap afterwards and every webhook in between fails verification, because it no longer carries a signature from the old secret.

Receiver side (single signature, e.g. GitHub)

GitHub sends a single X-Hub-Signature-256, and its docs describe no overlap mechanism. So the overlap lives on your side: hold both secrets and accept either.

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

// Only during the switch: new secret first, old one second
const SECRETS = [process.env.GITHUB_WEBHOOK_SECRET!, process.env.GITHUB_WEBHOOK_SECRET_OLD].filter(Boolean) as string[];

export function verifyGitHub(raw: Buffer, header: string | undefined): boolean {
  if (!header?.startsWith('sha256=')) return false;
  const got = Buffer.from(header.slice(7), 'hex');
  return SECRETS.some((s) => {
    const expected = createHmac('sha256', s).update(raw).digest();
    return got.length === expected.length && timingSafeEqual(got, expected);
  });
}

The order is: deploy the receiver with both secrets, change the secret in GitHub's webhook settings, confirm deliveries verify with the new one, then remove the old secret.

Leaked-secret runbook

  1. Scope it. Which endpoint's secret, and since when could someone else have seen it?
  2. Decide how fast to revoke. If a third party definitely has it, rotate with no overlap (in Stripe, expire the old secret immediately). Verification will fail until receivers update, but a sender with retries will redeliver those events once they do.
  3. Review what arrived in the meantime. Compare webhooks received between the leak and the rotation against the sender's delivery log, looking for events the sender never sent.
  4. Close the leak. A committed .env, a log line, a screen share: fix whatever exposed it.

If the sender keeps delivery logs and retries for several days, revoking immediately costs you nothing permanent: after the receiver updates, failed deliveries can be resent.

How Webhook Admin handles it

As of 2026-09-27:

  • Rotate from the dashboard, via POST /v1/endpoints/{id}/rotate-secret (API), or from the customer portal.
  • For 24 hours after a rotation, each delivery carries signatures from both the old and the new secret in webhook-signature (signature docs).
  • Secrets are generated by Webhook Admin when the endpoint is created (whsec_ plus 24 random bytes). You can't import a secret generated elsewhere.
  • Secrets are stored encrypted, and revealing one is recorded in the audit log.

Receivers verify with the official Standard Webhooks libraries, which already accept multiple signatures (Standard Webhooks explained). If you'd rather not build rotation and the rest of webhook sending yourself, try Webhook Admin free: https://app.webhookadmin.com/signup

Quick FAQ

How long should the overlap window be?

24 hours is a sensible default. Stripe allows up to 24 hours and Svix uses 24 hours. If the receivers are customers who need to change configuration on their side, announce the rotation in advance, because 24 hours can be tight for them.

If a secret leaks, should I revoke it immediately?

If you know a third party has it, yes, and accept that verification fails until receivers update. The sender's retries will redeliver the failed events afterwards. If it's only a possibility, rotate with a short overlap and ask receivers to update quickly.

What if the receiver runs on many servers?

Roll out the configuration that accepts both old and new secrets to every instance first, then switch the sender, then remove the old secret. Doing it in that order avoids a window where some instances reject valid webhooks.

Thanks for reading! When did you last rotate a webhook signing secret, and how did it go? Let us know in the comments.

This post first appeared on the Webhook Admin blog.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.