-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Description
Conflicting XFF and xff_trusted_cidr documentation
Description:
The current documentation for using xff_trusted_cidrs for selecting the trusted original address is as follows:
- If the remote address is contained by an entry in
xff_trusted_cidrs, and the last
(rightmost) entry is also contained by an entry inxff_trusted_cidrs, the trusted client
address is second-last IP address in XFF.
Based on the docs I'd expect the second to last IP address in the XFF header to be used as the original client address. The docs conflict with a later example:
Example 7: Envoy as edge proxy, with one trusted CIDR
Settings:
| use_remote_address = false
| xff_trusted_cidrs = 192.0.2.0/24
Request details:
| Downstream IP address = 192.0.2.5
| XFF = "203.0.113.128, 203.0.113.10, 192.0.2.1"
Result:
| Trusted client address = 192.0.2.1
| X-Envoy-External-Address is set to 192.0.2.1
| XFF is changed to "203.0.113.128, 203.0.113.10, 192.0.2.1, 192.0.2.5"
| X-Envoy-Internal is removed (if it was present in the incoming request)
Note the trusted client address is set to 192.0.2.1. Based on the documentation I would have expected the trusted client address to be set to 203.0.113.10. I thought maybe the second-last address was evaluated after appending the downstream IP address to the XFF but this also conflicts with a later example:
Example 8: Envoy as edge proxy, with two trusted CIDRs
Settings:
| use_remote_address = false
| xff_trusted_cidrs = 192.0.2.0/24, 198.51.100.0/24
Request details:
| Downstream IP address = 192.0.2.5
| XFF = "203.0.113.128, 203.0.113.10, 198.51.100.1"
Result:
| Trusted client address = 203.0.113.10
| X-Envoy-External-Address is set to 203.0.113.10
| XFF is changed to "203.0.113.128, 203.0.113.10, 198.51.100.1, 192.0.2.5"
| X-Envoy-Internal is removed (if it was present in the incoming request)
In example 8, the trusted client address is set to 203.0.113.10 which is the expected second-last XFF IP.
Could someone clarify the expected behavior and if this behavior verified in a unit test?