Fixes overlapping X-Forwarded-Prefix for chained path filters [server mvc] - #4238
Conversation
… mvc]
When multiple path-mutating filter functions (e.g. two StripPrefix
filters) process a request, each adds a snapshot to
MvcUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR and
XForwardedRequestHeadersFilter emitted one prefix per snapshot,
producing overlapping values such as "/tenant/api,/api". Downstream
forwarded-header processing concatenates the values and reconstructs a
wrong context path ("/tenant/api/api").
The prefix is now derived once, from the URL as received from the
client (the first entry of the attribute) against the final routed
path, so a single gateway contributes a single prefix while values
appended by upstream proxies are preserved.
Fixes spring-cloudgh-4237
Signed-off-by: Garvit Joshi <garvitjoshi9@gmail.com>
b77a6ab to
6f7d345
Compare
|
Additional context on why the duplicate A comma in an HTTP field represents a list separator; it does not itself mean path concatenation. Spring MVC performs the concatenation in String[] rawPrefixes = StringUtils.tokenizeToStringArray(result, ",");
for (String rawPrefix : rawPrefixes) {
// trailing slash handling omitted
prefix.append(rawPrefix);
}Therefore: X-Forwarded-Prefix: /tenant/api,/apiis interpreted as: The second |
Fixes gh-4237
When a Server MVC route applies more than one path-mutating filter (e.g.
StripPrefix=1twice), every filter function adds a snapshot of the request URL toMvcUtils.GATEWAY_ORIGINAL_REQUEST_URL_ATTR, andXForwardedRequestHeadersFilteremitted oneX-Forwarded-Prefixvalue per suffix-matching snapshot. For a request to/tenant/api/bluestripped to/blue, the downstream request carried:X-Forwarded-Prefix: /tenant/api,/apiDownstream forwarded-header processing concatenates comma-separated prefix values, so the downstream application reconstructs a wrong context path (
/tenant/api/apiinstead of/tenant/api).With this change the prefix is derived once, from the URL as received from the client (the first entry of the attribute, which is insertion-ordered) against the final routed path. A single gateway therefore contributes a single prefix value. Values appended by upstream proxies are still preserved, covered by a new test asserting
/upstream,/tenant/api.This is the Server MVC counterpart of gh-4236 (WebFlux), which is fixed separately so each module can be reviewed and backported independently.