DEV Community

Cover image for I built a webhook inspector with replay and mocks, and almost shipped three security bugs
ali
ali

Posted on

I built a webhook inspector with replay and mocks, and almost shipped three security bugs

Every developer who has integrated Stripe or GitHub webhooks knows the loop:
trigger an event, squint at logs, guess what the payload looked like, tweak the
handler, trigger again.

Hosted inspectors fix that, but your payloads (often with customer data) sit on
someone else's server. So I built Hookpit, a self-hostable webhook
inspector with replay and mock responses.

Hookpit dashboard with a captured Stripe-style webhook

What it does

  • One click gives you a capture URL; requests show up live
  • The raw body is stored exactly as sent
  • Replay any request to your own app, editing it first
  • Mock responses: make the URL behave like a fake API, with path patterns, placeholders like {{uuid}}, a configurable delay, and binary bodies
  • Per-IP rate limiting on replay and capture, with 429 and Retry-After

Four things I learned

1. Don't let the framework "help" with bodies. Express parses JSON and
throws away the original bytes. For an inspector (and for signature checks) you
need the raw body, so I disabled the parser on the capture route and wrote a
test with deliberately odd JSON.

2. Replay is an SSRF machine unless you stop it. Replay makes your server
fetch a URL a user typed. Type http://169.254.169.254/ on a cloud host and
you may read the instance's credentials. I blocked private and reserved
addresses (including IPv6-wrapped IPv4 like ::ffff:127.0.0.1), refused
redirects, and checked the address inside the DNS lookup used for the real
connection, so DNS rebinding can't swap it afterwards.

3. Mocks let users make your server say anything. That means stored XSS
(an HTML mock served from your origin), header injection (%0d%0a in a query
string ending up in a header), and template tricks ({{constructor}}). My
answers: force Content-Security-Policy: sandbox on every mock response, never
template headers, allow only plain property lookups in bodies, and cap how much
a template can expand.

4. Prove your tests can fail. For each protection I temporarily broke it and
watched the tests go red: 13 failures with SSRF protection off, 15 with header
validation off, 4 with prototype access allowed. A test that has never failed
might not test anything.

A bonus bug that only my laptop could find

CI was green, but docker compose up failed on my Apple Silicon Mac:
better-sqlite3 has no prebuilt binary for Node 20 on ARM Linux, so it tried to
compile and the slim image had no compiler. GitHub's runners are x86, so CI
could never see it. Fix: a build stage with the toolchain, copying only the
result into a slim final image.

The open-source part

Within days of posting the first good-first-issues, two strangers sent pull
requests, and both are merged: rate limiting, and binary mock bodies. I ran each
branch locally before merging. Reviewing taught me as much as writing the code:
I asked for a small test-cleanup fix in one, and in the other I found a gap in
the limiter (creating many endpoints sidesteps the per-endpoint limit), which is
now a public issue.

Try it


bash
git clone https://github.com/Aliweb789/hookpit.git
cd hookpit
docker compose up --build
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
userxnom profile image
Abdullah Naseer •

This is the rare build-in-public post where the security section is the actual product, not a footnote. The SSRF detail is what sold me β€” checking the address inside the DNS lookup used for the real connection, instead of validating a hostname and then resolving it again later, is exactly the rebinding trap most replay tools walk straight into, and catching ::ffff:127.0.0.1 shows you tested the sneaky cases, not just the textbook ones.

One thing I kept thinking about while reading the replay section: you store the raw body exactly as sent, which is the right call for signature checks, but the moment someone edits a payload before replaying, a Stripe-style signature stops verifying. Do you re-sign on replay, strip the signature header, or leave that as the user's problem to notice? And on the rate-limit gap you found in review β€” creating many endpoints sidestepping the per-endpoint limit β€” did you end up adding a per-IP global cap alongside it, or is that still the open issue?

The "prove your tests can fail" habit is worth stealing too. 13 red tests with SSRF protection off is a much stronger claim than "tests pass."

Collapse
 
ali_cf6b5e18547f5a5fbd326 profile image
ali •

Thanks, Abdullah, this is a great read of the article, and both questions are fair.

Signatures on replay: right now I forward the original headers as they were, signature header included, and don't re-sign or strip anything. So replaying an unedited request still verifies, and editing the body makes the signature fail, which is arguably useful for testing your handler's rejection path, but it isn't something the UI explains. The better answer is probably an option on the replay panel: keep the original signature, strip it, or re-sign with a secret you supply (Stripe-style first, since it's well documented). Signature verification is on the roadmap, and I'd build re-signing alongside it. I opened github.com/Aliweb789/hookpit/issue... for exactly this, thanks to your question.

Rate limit: still open. The per-endpoint limit shipped, and the global per-IP cap plus limiting endpoint creation is tracked here: github.com/Aliweb789/hookpit/issue.... I'd rather say it's a known gap than pretend the limiter is complete.

And thanks for the note on the tests. Breaking each protection on purpose and seeing it fail was the most convincing check I did.