Why a rotation refuses deliveries#
An HMAC webhook has two holders of one secret. The sender computes an HMAC of the request body with the secret and sends it in a header; GitHub uses X-Hub-Signature-256 with SHA-256. The receiver computes the same HMAC over the body it received and compares the two in constant time, as GitHub's validation guide shows. A mismatch should get a 401, because an unsigned or wrongly signed request may be forged.
A rotation changes the secret in two places that nobody can update atomically. The sender's value lives in a settings page or an API. The receiver's value lives in a secret store, and most services read it once when an instance starts, so it reaches traffic only when new instances replace old ones. A secret rotated during a rollout shows the same effect from the receiver's side: instances started at different times hold different values.
Whichever side moves first, the deliveries in between carry a signature the receiver cannot match. The gap lasts as long as the slower of the two changes, and it is longer if one of them silently fails.
Refusals are not retried#
Senders differ in what they do with a 401. GitHub records it as a failed delivery and stops: GitHub does not automatically redeliver failed webhook deliveries, and it keeps deliveries for redelivery for three days. Each refused event is lost until somebody lists the failed deliveries and asks for each one again, and that redelivery runs into the API's own rate limits.
So treat a signature refusal during a rotation as data loss with a deadline, not as noise. A burst of refusals that starts within seconds of a secret change is the rotation; a few refusals spread over days have some other cause.
Overlap on the side that can hold two secrets#
The fix is a period in which both secrets verify. Someone has to hold two, and which side that is depends on the sender.
Some senders hold both. Stripe lets you roll an endpoint's secret with the old one kept for up to seven days, and during that time it sends one signature per active secret. A receiver that still has only the old secret keeps matching one of them.
GitHub's webhook settings hold a single secret, so the overlap has to live in the receiver. The receiver keeps a list of accepted secrets and tries each one. The rotation then runs in four steps:
- Add the new secret to the receiver's list, next to the old one. Roll it out to every instance.
- Change the sender to the new secret.
- Confirm a delivery verifies with the new secret. Then watch for deliveries that match the old one throughout the expected in-flight and redelivery window.
- Remove the old secret from the receiver's list.
Step 3 is what makes the procedure observable. Log or count which entry in the list matched (its position, never its value). On a quiet endpoint, trigger an expected delivery to observe the new secret before starting the watch.
The lab#
The lab runs a receiver and a sender in one Python process and needs only Docker. The receiver checks X-Hub-Signature-256 against every secret in accepted.
import hashlib, hmac, http.server, threading, urllib.error, urllib.request
accepted = [b"old-secret"] # secrets the receiver accepts, newest first
def signature(secret, body):
return "sha256=" + hmac.new(secret, body, hashlib.sha256).hexdigest()
class Receiver(http.server.BaseHTTPRequestHandler):
def do_POST(self):
body = self.rfile.read(int(self.headers["Content-Length"]))
sent = self.headers.get("X-Hub-Signature-256", "")
ok = any(hmac.compare_digest(signature(s, body), sent) for s in accepted)
self.send_response(202 if ok else 401)
self.end_headers()
def log_message(self, *args):
pass
server = http.server.HTTPServer(("127.0.0.1", 0), Receiver)
threading.Thread(target=server.serve_forever, daemon=True).start()
def deliver(sender_secret, n=3):
codes = []
for i in range(n):
body = b'{"action":"opened","number":%d}' % i
req = urllib.request.Request(f"http://127.0.0.1:{server.server_port}/hook", body,
{"X-Hub-Signature-256": signature(sender_secret, body)})
try:
codes.append(urllib.request.urlopen(req).status)
except urllib.error.HTTPError as e:
codes.append(e.code)
return codes
old, new = b"old-secret", b"new-secret"
print("receiver-first rotation")
accepted[:] = [new]
print(" receiver holds new, sender signs old:", deliver(old))
print("overlap rotation")
accepted[:] = [old]
print(" 1. both on old: ", deliver(old))
accepted[:] = [new, old]
print(" 2. receiver accepts new and old: ", deliver(old))
print(" 3. sender switches to new: ", deliver(new))
accepted[:] = [new]
print(" 4. receiver drops old: ", deliver(new))
print(" a delivery still signed with old: ", deliver(old, 1))
Save it as rotate.py and run it:
docker run --rm -v "$PWD":/lab:ro python:3 python3 /lab/rotate.py
receiver-first rotation
receiver holds new, sender signs old: [401, 401, 401]
overlap rotation
1. both on old: [202, 202, 202]
2. receiver accepts new and old: [202, 202, 202]
3. sender switches to new: [202, 202, 202]
4. receiver drops old: [202, 202, 202]
a delivery still signed with old: [401]
The receiver-first rotation refuses everything until the sender catches up. The overlap rotation answers 202 at every step, whatever the delay between steps 2 and 3. The last line is the reason to wait before step 4: a delivery the sender signed before its switch, still in flight or queued for retry, fails once the old secret is gone.
Each extra secret is one more HMAC per refused request, and a list of two adds no meaningful work to an accepted one. Keep the list short and remove the old entry; a receiver that accepts every secret it ever had keeps a leaked one valid.
A real rotation#
In the production case behind this guide, an operator rotated the signing secret of a GitHub App's webhook. A new revision of the receiving service started on the new secret two seconds after the new version was stored. The first save of the new value in the App's settings did not take, so GitHub kept signing with the old one. The new revision answered 2,197 deliveries with 401 over five and a half minutes: 149, 328, 366, 323, 599 and 432 in successive minutes. Its instance began answering 202 without a restart once a second save reached GitHub.
None of those deliveries came back on their own. Redelivering them through GitHub's API hit its secondary rate limit after 1,299 requests, and the other 898 went through over the following seven minutes. Each redelivery keeps its original delivery ID, so a receiver that records delivery IDs can redeliver a window without processing an event twice.
If you cannot hold two secrets#
Some receivers cannot take a list without a code change. Then shorten the gap and plan the recovery:
- Change the sender and start the receiver's new instances within the same minute, and read the receiver's request log until it answers the sender with 2xx again.
- Alert on a burst of signature refusals, with a threshold above the occasional refusal a public endpoint sees on a normal day.
- Redeliver the refused window afterwards, inside the sender's retention period, and confirm that every refused delivery ID has a successful attempt.
The same overlap applies to other shared secrets with two holders, such as signing keys for tokens; a JWT rejected after a key rotation is the token-side version of this failure.
Where this came from#
Proofline found this in a rotation of its own webhook signing secret and shipped an alert on bursts of signature refusals, with a written rotation and redelivery procedure, in its production release of 18 November 2026. The counts in A real rotation come from that service's request log. Proofline reviews GitHub pull requests; new organizations get one calendar month of hosted code review without a cloud connection. Start a free GitHub review ยท Eligibility and fair-use terms
Questions#
Does GitHub retry a webhook that got a 401?
No. GitHub records the 401 as a failed delivery and does not redeliver it automatically. You can redeliver deliveries from the past three days in the App's or webhook's settings or through the REST API.
Can a GitHub webhook have two secrets at once?
No, its settings hold one secret. Put the overlap in your receiver by accepting a short list of secrets during the rotation.
How do I know the sender has switched to the new secret?
Count which secret matched each delivery, by position. After a successful match on the new secret, wait until the old secret has seen no matches through the expected queue and redelivery window before removing it.