-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
ForwardedRequestCustomizer
setters do not clear existing handlers
#7975
Comments
we ran into the same issue with 10.0.9, i've added a Test, not sure i'm not sure what would be the best approach: this is topic is potentially security relevant .. |
…les when renaming headers. * Adding test case to prove report * Fixing updateHandles() to clear the stored handles list. Signed-off-by: Joakim Erdfelt <[email protected]>
Opened PR #8102 |
…les when renaming headers. (#8102) * Adding test case to prove report * Fixing updateHandles() to clear the stored handles list. Signed-off-by: Joakim Erdfelt <[email protected]>
Jetty version(s)
10.0.8
Java version/vendor
(use: java -version)
openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.1+13)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.1+13, mixed mode)
OS type/version
macOS Monterey Version 12.1
Description
We use ForwardedRequestCustomizer to dynamically configure the header to use instead of "X-Forwarded-For" to determine the IP address for a clients request. We use
ForwardedRequestCustomizer.setForwardedForHeader
to set a custom header to use instead ofX-Forwarded-For
. After updating from Jetty version 9.4.44 to 10.0.8 we saw an issue where, depending on the ordering of headers, a request would have a different remote address.In the code for 9.4.44, the
updateHandles
function inForwardedRequestCustomizer
would always reinstantiate_handles
before setting the headers that mapped to each handler (code link). What this meant is that usingsetForwardedForHeader
would mean that the only header that would cause the "handleForwardedFor" handler to run would be the one specified viasetForwardedForHeader
. However after the upgrade to 10.0.8 the existing handlers in_handles
never get cleared. Instead theupdateHandles
function will just add a new header to handle mapping that will run "handleForwardedFor" (code). What this means is that both the custom header we specify and "X-Forwarded-For" can be used to calculate the remote address for a request. We even saw some confusing behavior where, based on the order of the headers in the request a different remote address would be calculated (likely due to HttpFields being process in the specified order)This looks like what could have also caused the issue in this other bug: #7026. We can take a similar approach to what you suggested in that issue and override the getter for
getForwardedForHeader
, but the behavior of the setters is still confusing. It would be good if the setters on ForwardedRequestCustomizer would clear the existing header to handler mappings before applying the new ones (similar to what was done in version 9.4).How to reproduce?
Now depending on the order of headers, a different remote address will be calculated
Log looks like the following, showing that the remote address is considered 1.1.1.1
Log looks like the following, showing that the remote address is considered 2.2.2.2
The text was updated successfully, but these errors were encountered: