Hi! I would like to ensure that requests indicating to be proxied / forwarded which do not match the trusted_proxies + trusted_proxies_strict configuration to not be served at all.
I am currently using the following snippet to abort requests that have a X-Forwarded-IP header but do not yield a real client_ip different from the remote host address.
While this somewhat does what I want it to do it is a rather fragile solution. It would be better if we could receive the result of the trusted_proxies evaluation directly somehow. Is there a way this can be achieved?
Rather than trying to see if the client IP and remote IP are the same, you can simply check if the immediate peer is one of the trusted proxies with remote_ip private_ranges, e.g.
@is_untrusted_proxy {
header X-Forwarded-For
not remote_ip private_ranges
}
This isn’t “receiving the result of the trusted_proxies evaluation” per se, but it’s running an identical evaluation all the same, because your trusted_proxies are private_ranges anyway.
P.S.:
Is this meant to be {remote_ip} instead of {remote_host}?
Using the remote_ip matcher sounds like a decent idea for this example. I am not too sure if this would scale to using non static trusted_proxy providers like this cloudflare one, unless there is some way to retrieve its utilized ips.
{remote_host} describes the shorthand for the placeholder {http.request.remote.host}.