Surprising X-Forwarded-Prefix transform behavior #2354
-
I have an asp.net core backend server with YARP in front. I am forwarding requests and stripping the path base when it forwards on. I am able to get it working but was confused on one bit.
new RouteConfig
{
ClusterId = GetCluster(proxy.Path),
RouteId = $"{proxy.Path}_route",
Match = new RouteMatch
{
Path = $"/{proxy.Path}/{{**catchall}}",
Hosts = new []
{
host
}
},
Transforms = new List<Dictionary<string, string>> { }
}
.WithTransformPathRemovePrefix($"/{proxy.Path}")
.WithTransformRequestHeader("X-Forwarded-Prefix", $"/{proxy.Path}")
.WithTransformXForwarded() // Why this is required? Why is the Is this correct behavior? I may be misunderstanding correct usage of this API. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
That's correct, if |
Beta Was this translation helpful? Give feedback.
-
This is way worse. The documentation states that the x-forwarded are added by default. They are as long as you do absolutely no transforms at all. Then, if you do, the x-forwarded are also not sent which breaks everything. And there doesn't appear to be a global way to put back x-forwarded-*. this:
Adds "forwarded" header which the segments ; separated, which asp.net core's middleware doesn't understand and is broken, and it adds x-original-* not x-forwarded-for despite using AddXForwarded, which asp.net core's middleware also doesn't understand. further adding this:
Doesn't actually result in the asp.net core getting these request headers. Which borks the entire thing. Only doing this in your transforms in your json config:
Actually works. So the documentation is both wrong, and the behavior is broken. These should be ALWAYS sent unless explicilty turned off and just setting transforms to do things like strip a path shouldn't be breaking this. |
Beta Was this translation helpful? Give feedback.
That's correct, if
WithTransformXForwarded
isn't called, all theX-Forwarded-*
headers are stripped if present, and not added.