Skip to content

Check the destination of requests sent through a forward proxy - #116

Merged
andrew merged 1 commit into
git-pkgs:mainfrom
simonchrz:fix/safehttp-forward-proxy
Oct 24, 2026
Merged

andrew merged 1 commit into
git-pkgs:mainfrom
simonchrz:fix/safehttp-forward-proxy

Conversation

@simonchrz

Copy link
Copy Markdown
Contributor

safehttp.New clones http.DefaultTransport, which keeps ProxyFromEnvironment, and the address gate only wraps DialContext. With HTTP_PROXY or HTTPS_PROXY set, the dial goes to the forward proxy, so only the forward proxy's address was checked, never the destination's.

newClient now wraps transport.Proxy next to the dial gate. When a request is sent to a forward proxy, the destination host is resolved (IP literals are used as is) and every address has to pass the same gate with the same Options, so link-local stays blocked and AllowLoopback, AllowPrivate and AllowPrivateHosts behave as for direct requests. A name that can't be resolved locally is still passed to the forward proxy, since some networks resolve public names only there. Direct requests are unchanged, and the TinyGo client is not affected.

The tests route a client through a loopback forward proxy with a fake resolver: link-local and private destinations (literals and names) are refused before reaching it, while allowlisted private hosts, public hosts and unresolvable names go through.

Fixes #115

safehttp.New clones http.DefaultTransport, which keeps
ProxyFromEnvironment, and the address gate only wraps DialContext. With
HTTP_PROXY or HTTPS_PROXY set the transport dials the forward proxy, so
the gate checked the forward proxy's address and never the destination.

newClient now also wraps transport.Proxy: for a request that goes to a
forward proxy, the destination host is resolved and every address has
to pass the same gate with the same Options. A name that cannot be
resolved locally is still passed on, since some networks resolve public
names only at the forward proxy. Direct requests are unchanged, and the
TinyGo client is not affected.

Fixes git-pkgs#115
@andrew
andrew merged commit efc46e3 into git-pkgs:main Oct 24, 2026
3 checks passed
simonchrz added a commit to simonchrz/proxy that referenced this pull request Oct 24, 2026
registries' safehttp now checks the destination of requests sent through
a forward proxy (git-pkgs/registries#116), so the proxy's own guard is
removed and newUpstreamClient is back to its earlier form.

go.mod points at a pseudo-version of registries main until git-pkgs#116 is
released.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

safehttp: check the destination of requests sent through a forward proxy

2 participants