Skip to content

reverseproxy: Avoid returning an error if host address is not an IP address #6985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
JordiSubira opened this issue Apr 24, 2025 · 0 comments

Comments

@JordiSubira
Copy link

JordiSubira commented Apr 24, 2025

I am using the reverseproxy module with a custom underlay network, more concretely a SCION network. The SCION underlay network doesn't use IP addresses as host addresses. More concretely, the retrieved addrPort value on https://github.com/caddyserver/caddy/blob/v2.9.0-beta.3/modules/caddyhttp/reverseproxy/reverseproxy.go#L687 will yield and address of the following format [isd-as,ipv4]:port or [isd-as,ipv6%zone]:port.

An error is returned on https://github.com/caddyserver/caddy/blob/v2.9.0-beta.3/modules/caddyhttp/reverseproxy/reverseproxy.go#L740 after netip.ParseAddr(clientIP), in turn, returns an error. I would suggest to ignore the trusted proxy check if netip.ParseAddr(clientIP) returns an error, for example something similar to this:

...
trusted := caddyhttp.GetVar(req.Context(), caddyhttp.TrustedProxyVarKey).(bool)
clientIP, _, _ = strings.Cut(clientIP, "%")
ipAddr, err := netip.ParseAddr(clientIP)
if err == nil {
	// Check if the client is a trusted proxy
	for _, ipRange := range h.trustedProxies {
		if ipRange.Contains(ipAddr) {
			trusted = true
			break
		}
	}
}
...

Note that SplitHostPort here is able to split non-ip hosts, so it seems more appropriate to consider that the host address is not necessarily an IP address .This change would maintain the current behavior (meaning that it would not break something that is already working) while allowing for other host address types.

@JordiSubira JordiSubira changed the title reverseproxy: Avoid returning an error if clientIP is not an IP address reverseproxy: Avoid returning an error if host address is not an IP address Apr 24, 2025
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

No branches or pull requests

1 participant