Add X-Forwarded-For proxy header#5
Conversation
|
@mikejhill thanks for the patch, I'll review it tomorrow. |
machak
left a comment
There was a problem hiding this comment.
Code looks ok other than part I commented (appending first address as last again)
|
The options's called addProxyHeaders, so should X-Forwarded-Proto and X-Forwarded-Host then be forwarded/appended as well? |
I've added additional options for X-Forwarded-Proto, X-Forwarded-Host, X-Forwarded-By, and Host (for manually propagating the host value) now. I also changed the I found myself needing differing headers depending on my configuration. For example, |
In addition to the existing X-Forwarded-For, adds support for: - Host - X-Forwarded-By - X-Forwarded-Host - X-Forwarded-Proto
8eb2779 to
a8960b2
Compare
|
Made some minor updates, added |
Targeting this fork since it seems to be the most active of UrlRewriteFilter and has been a really helpful fork for us so far (thank you for your work!).
This tries to fix an issue into where (reverse-)proxying doesn't include the X-Forwarded-For header. This header propagates the original client IP to downstream targets. This need for us comes out of a simple (Atlassian Crowd) SSO solution that requires validating an SSO token against a matching client IP. Hosts need to see the real client IP during proxied requests rather than just the proxy (UrlRewriteFilter) server's IP.
MDN X-Forwarded-For page: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For
There seems to be some question on whether X-Forwarded-For or X-Real-IP is a better header to use (source). However, MDN doesn't list X-Real-IP, and I don't seem to see it used as often in other places. The Tomcat RemoteIpValve uses X-Forwarded-For, X-Forwarded-By, and X-Forwarded-Proto only, by default. NGINX mentions X-Real-IP in some of their guides, but seems to prefer X-Forwarded-For (e.g.,
$proxy_add_x_forwarded_for). I don't see any mention of X-Real-IP in the org.apache.tomcat:tomcat-catalina:9.0.30 source.