Repository navigation
Conversation
Add a flag to only fetch remote images from publicly routable IP addresses. DenyHosts CIDR entries only match IPs written in the URL, so a hostname resolving to a private address (an internal name, a wildcard DNS service like nip.io, DNS rebinding) or a redirect to one is still fetched. Instead, check the address in the dialer's Control function, after DNS resolution, on every connection including redirects. The check fails closed: IPv4 addresses in IANA special-purpose ranges that are not globally reachable, multicast and reserved space are refused; IPv6 must be global unicast (2000::/3) outside its non-global blocks. NAT64 and 6to4 addresses are checked against their embedded IPv4 address, and scoped IPv6 addresses are refused. When enabled, HTTP_PROXY is ignored (the proxy would be the address checked) and the AIA transport is replaced, since its TLS dialer and issuer certificate fetches would bypass the check. Also stop including the fetch error in the response to clients: it can name internal addresses and ports. It is still logged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
-denyPrivateNetworksflag (off by default;IMAGEPROXY_DENYPRIVATENETWORKS=truealso works) so imageproxy only fetches remote images from publicly routable IP addresses.Why
#72 asked for a way to stop imageproxy from requesting itself and other services on the same private network, and was resolved with
denyHosts. CIDR entries indenyHostsonly match IP addresses written in the URL, though, so these are still fetched:With the image proxy running in a cloud environment, that includes the instance metadata endpoint (
169.254.169.254). Even whencontentTypeskeeps the response from being returned, the request is still made.How it works
The check runs in the dialer's
Controlfunction, on the address actually connected to after DNS resolution, for every connection including each redirect hop.It fails closed: only addresses known to be public are allowed.
2000::/3), minus its non-global blocks (Teredo, documentation). NAT64 (64:ff9b::/96) and 6to4 addresses are checked against their embedded IPv4 address. IPv4-mapped addresses are checked as IPv4. Scoped addresses (fe80::1%eth0) are refused.Side effects when enabled
These are documented in the README and the flag's help text:
HTTP_PROXY/HTTPS_PROXYare ignored, since the proxy would be the address checked instead of the origin.http.Get, both of which would bypass the check, so origins serving an incomplete certificate chain will fail.Also changed
When fetching the remote image fails, clients now get a generic
error fetching remote imageinstead of the full error, which can name internal addresses and ports (and whether a port is open). The details are still logged. This applies with or without the flag. I'm happy to limit it to the flag, or split it into a separate PR, if you prefer.Scope
The flag is wired into
cmd/imageproxyonly. The Caddy module doesn't get it. Moving the transport into the library package so the Caddy module can use it would be a small follow-up if you'd like that.Testing
go test -race ./..., staticcheck and golangci-lint pass, andGOOS=windows go vetis clean.cmd/imageproxy/egress_test.go: a table of allowed and blocked IPv4 and IPv6 forms asserting on the specific error, and a transport test that reaches the same loopback origin with and without the check.localhost,*.nip.io/*.sslip.ionames resolving to private addresses, zone-scoped IPv6 and169.254.169.254are refused. Clients get the generic error and the log names the blocked address.🤖 Generated with Claude Code