Since v0.18.0, a zgrok tunnel runs a request inspector on your machine, at http://127.0.0.1:4040. It shows each request that came through, with its headers and body, and it can replay one against your app.
It binds to loopback only, so another device on your network cannot connect to it. That sounds like the end of the security question. It is not, because your browser is on your machine too, and it runs code from any site you open.
If you have ever written a dev tool with a local web UI, this is probably about you as well.
Attack 1: the name that moves
A browser decides who may read a response by origin: scheme, host and port. A page on http://evil.test:4040 cannot read http://127.0.0.1:4040, because the host is different.
The browser compares the name, though, and not the address behind it. So:
- You open a page on
http://evil.test:4040. Its DNS answer is the attacker's server, with a lifetime of a second. - The attacker changes the answer to
127.0.0.1. - The page calls
fetch("/api/requests"). The name is the same, so the origin is the same. The request goes to your machine.
This is DNS rebinding. The port was never reachable from outside, and it did not need to be. Your browser made the request, from inside, and hands the response to the page.
What gives it away is the Host header. The browser still believes it is talking to evil.test:4040, and says so. The fix is to refuse any request whose Host is not a loopback name:
const LOCAL = /^(127\.0\.0\.1|localhost|\[::1\])(:\d+)?$/i;
if (!LOCAL.test(request.headers.get("host") ?? "")) {
return new Response("forbidden", { status: 403 });
}A missing Host is refused too. A check that lets the odd case through is not doing its job.
You can test any local tool for this in a few seconds:
curl -i -H "Host: evil.example" http://127.0.0.1:4040/api/requestsIf that returns data, a rebinding page could read it, unless something else stops it. zgrok's inspector answers:
{"error":"the inspector answers only to a loopback Host (127.0.0.1, localhost, [::1])"}We caught this one before release, in a review of the whole branch. The reviews of each part had passed. Each part was fine, and the hole was in what nobody had added.
Attack 2: the request that needs no answer
The same-origin rule stops a page from reading your localhost. It does not stop it from sending.
Replay is POST /api/requests/7/replay, with no body and no custom headers. To a browser that is a simple request, the kind an HTML form could make, so it goes out with no preflight. The page cannot see the response. It does not care. Your dev app has just processed a webhook a second time.
The Host check does not help. The page asks for 127.0.0.1:4040 honestly, so the Host is right. What differs is the Origin header, which says where the request came from, so replay checks it.
Where we got it wrong
Our first version asked: is this Origin a loopback address? A page on evil.test fails that, and we shipped it.
But the other dev servers on your machine are loopback too. Anything on localhost:4999, say a project you cloned this morning and ran to have a look, passed the check and could trigger a replay. It stayed that way from v0.18.0 until v0.26.1, when we fixed it and published an advisory. We have no evidence that anyone used it.
The right question is narrower: is this Origin the inspector itself? The answer needs no configuration, because both halves are in the request:
const origin = request.headers.get("origin");
const host = request.headers.get("host");
if (origin !== null && origin !== `http://${host}`) {
return new Response("forbidden", { status: 403 });
}That pins the port as well, even though our inspector moves to the next free port when 4040 is taken. An absent Origin is allowed on purpose: curl does not send one, and browsers send it on a POST.
Attack 3: the click you did not mean
Suppose a page loads the real inspector in an invisible frame, puts its Replay button under your cursor, and asks you to click something else. The request now comes from the inspector's own page. Host is right. Origin is right. Both checks pass, and they are correct to pass.
The defence is to refuse the frame:
Content-Security-Policy: frame-ancestors 'none'
X-Frame-Options: DENYWe added these in the same release as the Origin fix.
What each check stops
We tested four versions of a small server in Chrome 158, then the real CLI's inspector.
| Check | Rebound name reads data | evil.test triggers replay | Another local port triggers replay |
|---|---|---|---|
| None, loopback bind only | yes | yes | yes |
Host is loopback | no | yes | yes |
plus Origin is loopback | no | no | yes |
plus Origin is itself | no | no | no |
The third row is what we shipped first. The real inspector matched the last row, refused to load in a frame, and still replayed from its own button and from a client that sends no Origin.
Two limits of the test. The rebinding column was run for the first two rows; the last two keep the same Host check. And we did not run a DNS server that changes its answer. Chrome was told that evil.test is 127.0.0.1, and we swapped the server behind the port after the page had loaded. So every page in it came from a loopback address.
Doesn't the browser handle this now?
Partly. Chrome has been adding Local Network Access, which asks for permission before a page from the public internet sends a request to a local address. Its announcement gives Chrome 142 as the launch.
It is a welcome layer, and we would not rely on it alone. The announcement scopes its first version to requests from a public address to a local one, so one local port calling another, which is the case we got wrong, is outside it. And a permission prompt is a question people can answer yes to.
If your tool listens on localhost
- Refuse a
Hostyou do not recognise, on every route. - On anything that changes state, refuse an
Originthat is not your own. - Send
frame-ancestors 'none'.
That is three short checks. Binding to loopback keeps other machines out. These keep other pages out. The request inspector docs describe what ours does. If your zgrok is older than v0.26.1, run the installer from the download page again: the built-in updater in some of those versions no longer works.
