-
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 / getLeftMost #5484
Comments
(currently we use 9.4.31) |
What does that mean? Can you explain the issue around "limit the number of IPs in that header"? A small example of this would be a request that has gone through 2 proxies before hitting Jetty.
That class has undergone a fair bit of a rework recently in 9.4.33. Can you provide, instead, some example requests where this is an issue? |
Hi, our case is the following:
while getLeftMost() will now select 10.1.1.1, which i do not want, because i know, that that is injected from the outside, and in my logs i need the endpoints of the tcp connection to on the LoadBalancer (last point of our infrastructure) so that test would look like:
|
Ugh, that's a gross violation of various specs. (even the ones that are not specs, like Fixing it via getLeftMost isn't going to work reliably (as that method is used for many fields, not just But all is not lost, do this instead ... Keep your extension of ForwardRequestCustomizer. But override Then fix the specific headers in Something like this ... package jetty.forwarding;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.ForwardedRequestCustomizer;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.Request;
public class OutOfSpecForwardingHeaders extends ForwardedRequestCustomizer
{
@Override
public void customize(Connector connector, HttpConfiguration config, Request request)
{
HttpFields fields = request.getHttpFields();
HttpField xForwardedForField = fields.getField(HttpHeader.X_FORWARDED_FOR);
// make sure field exists
if (xForwardedForField != null)
{
// We are interested in the second value.
String[] values = xForwardedForField.getValues();
if (values != null && values.length >= 2)
{
// Only update if there is actually 2 or more values present
String second = values[1];
fields.put(HttpHeader.X_FORWARDED_FOR, second);
}
}
super.customize(connector, config, request);
}
} |
ok, thanks. |
I updated the example for you. |
Heh, it is actually easier to implement then my prior example, I forgot we were dealing with HttpField (which has proper field value list logic built-in). |
Hi
in our code we overwrote getLeftMost so we could limit the Number of IPs in that Header as, e.g. AWS/ApplicationLB does not replace, but append to the Header if the outside request contains it already. But as that part is untrusted, we want to limit the how many levels we accept.
in #5247 this method is made static, so we can not override it anymore.
if your are interessted we can also submit a merge request with our depth-limiting code.
Best,
Georg
The text was updated successfully, but these errors were encountered: