Bug Description
Fiber only strips of the first TrustedProxy IP from the ProxyHeader (typically X-Forwarded-For).
It should keep stripping off TrustedProxy IPs until it reaches the first non-trusted IP.
The doc now says:
Behavior note: X-Forwarded-For often contains a comma-separated chain of IP addresses. With the default EnableIPValidation = false, c.IP() will return the raw header value (the whole chain) rather than a single parsed client IP. With EnableIPValidation = true, c.IP() parses the header and returns the first syntactically valid IP address it finds; it does not walk the chain to find the first non-proxy hop. For a reliable client IP, configure your reverse proxy to overwrite or sanitize this header and/or to provide a single-IP header such as "X-Real-IP" or a provider-specific header like "CF-Connecting-IP".
Why does the code not walk the chain to find the first non-proxy hop?
How to Reproduce
Steps to reproduce the behavior:
- Configure Fiber with TrustedProxy subnets: "2001:db8::/32", "192.168.0.0/24".
- Send a
X-Forwarded-For request header with 1.2.3.4, 2001:db8::10, 192.168.0.10
- c.IP() now returns
1.2.3.4, 2001:db8::10
Expected Behavior
As mentioned in https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Forwarded-For
The header can contain N-proxies:
X-Forwarded-For: <client>, <proxy>
X-Forwarded-For: <client>, <proxy>, …, <proxyN>
The server should strip all trusted proxy addresses from the list.
Fiber Version
v2.52.13
Code Snippet (optional)
Checklist:
Bug Description
Fiber only strips of the first TrustedProxy IP from the ProxyHeader (typically
X-Forwarded-For).It should keep stripping off TrustedProxy IPs until it reaches the first non-trusted IP.
The doc now says:
Why does the code not walk the chain to find the first non-proxy hop?
How to Reproduce
Steps to reproduce the behavior:
X-Forwarded-Forrequest header with1.2.3.4, 2001:db8::10, 192.168.0.101.2.3.4, 2001:db8::10Expected Behavior
As mentioned in https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/X-Forwarded-For
The header can contain N-proxies:
The server should strip all trusted proxy addresses from the list.
Fiber Version
v2.52.13
Code Snippet (optional)
Checklist: