Guide

GitHub webhooks: receive repo and org events locally and validate the secret

GitHub webhooks send an HTTP POST when something happens in a repository or organization: a push, a pull request, an issue, a workflow run. GitHub needs a public URL to deliver to. Here is how to point a repo or org webhook at a URL you can inspect, validate the secret and redeliver events while you build the handler.

All docs

Get a public URL for GitHub webhooks#

GitHub can't deliver to localhost. An OtterKit webhook endpoint gives you a public HTTPS URL that answers GitHub around the clock and keeps every request, so nothing is lost while your laptop is closed or your handler is half written:

Terminal
npx otterkit login
npx otterkit webhook --daemon --subdomain gh-dev
#   https://gh-dev.otterkit.app

The name is reserved to your account, so the URL stays the same every time you start it. An endpoint costs $0.01 per hour while it is live and never more than $3 in any 30 days, and new accounts get 10 free credits. To look at a payload before you sign up, the try page gives you a live URL in the browser with no account.

Register the URL in GitHub#

  1. For one repository, open its Settings, then Webhooks, and click Add webhook. For every repository in an organization, do the same from the organization's settings.
  2. Paste the endpoint URL as the Payload URL and set the content type to application/json.
  3. Type a long random string as the Secret, pick the events you want and save. GitHub sends a ping event straight away.

Use https://gh-dev.otterkit.app as the URL. Add a path if your handler expects one, such as https://gh-dev.otterkit.app/hooks/github: the endpoint accepts any path and records it.

Validate the webhook secret#

You choose the secret; GitHub never shows it again. With a secret set, each delivery carries X-Hub-Signature-256: the text sha256= followed by the hex HMAC-SHA256 of the raw body. Compute the same value and compare with a constant-time function.

Two more headers are worth logging: X-GitHub-Event names the event, and X-GitHub-Delivery is a unique ID you can use to ignore duplicates.

OtterKit can run the same check on every request as it arrives. Start the endpoint again with the secret, and each capture is marked valid, invalid or missing:

Terminal
npx otterkit stop gh-dev
npx otterkit webhook --daemon --subdomain gh-dev --verify github:my-webhook-secret

A failed check comes with its reason, such as signature_mismatch, so a wrong secret and a changed body look different. See signature verification for all 16 presets and the generic HMAC mode.

Send a test event#

The ping that GitHub sends when you save the webhook is your first test. After that, push a commit or open an issue in a scratch repository.

Then watch it land, or wait for it in a script:

Terminal
# Follow requests as they arrive, with headers and bodies
npx otterkit inspect gh-dev --follow

# Or block until the next POST, then print it as JSON
npx otterkit await gh-dev --method POST --count 1 --timeout 120s --json

You can also skip GitHub entirely. otterkit send builds a sample event, signs it with your secret the way GitHub does and posts it straight to your local handler:

Terminal
npx otterkit send github:push 127.0.0.1:3000/hooks/github \
  --secret my-webhook-secret

Replay GitHub events into your local handler#

Once an event is captured you can send it to your handler as often as you like, with the original headers and body, without asking GitHub to fire it again:

Terminal
# Send the latest captured event to a server on port 3000
npx otterkit replay gh-dev --target 127.0.0.1:3000

# Or a specific one (1 is the oldest, -1 the latest)
npx otterkit replay gh-dev --index 3 --target 127.0.0.1:3000

Replays cost nothing and are added to the capture log with your handler's response next to them. If you would rather have events delivered live while you work, expose the handler with a tunnel instead and register the tunnel URL.

Retries, timeouts and duplicates#

  • GitHub waits about ten seconds for a response and does not retry a failed delivery by itself. Open the webhook's Recent Deliveries tab to see each request and response, and click Redeliver to send one again.
  • Because there are no automatic retries, an endpoint that is always up matters more here than with most providers.

To see how your code copes when a delivery fails, the HTTP status codes guide has URLs that return any status on demand.

Questions about GitHub webhooks#

What is the difference between repo and org webhooks?#

A repository webhook fires for that repository only. An organization webhook fires for every repository in it and adds organization events such as membership changes. The payloads and signatures work the same way.

Should I check X-Hub-Signature or X-Hub-Signature-256?#

X-Hub-Signature-256. The older header uses SHA-1 and is only sent for compatibility.

Do GitHub App webhooks work the same way?#

Yes. The URL and secret are set on the app's settings page instead, and the deliveries carry the same headers.

Other providers#