Fixes overlapping X-Forwarded-Prefix for chained path filters [webflux]#4239
Fixes overlapping X-Forwarded-Prefix for chained path filters [webflux]#4239garvit-joshi wants to merge 1 commit into
Conversation
When multiple path-mutating filters (e.g. two StripPrefix filters)
process a request, each adds a snapshot to
GATEWAY_ORIGINAL_REQUEST_URL_ATTR and XForwardedHeadersFilter 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-4236
Signed-off-by: Garvit Joshi <garvitjoshi9@gmail.com>
|
Additional context on why the duplicate A comma in an HTTP field represents a list separator; it does not itself mean path concatenation. Spring WebFlux performs the concatenation in String[] rawPrefixes = StringUtils.tokenizeToStringArray(header, ",");
for (String rawPrefix : rawPrefixes) {
// trailing slash handling omitted
prefix.append(rawPrefix);
}Therefore: X-Forwarded-Prefix: /tenant/api,/apiis interpreted as: The second |
Fixes gh-4236
When a WebFlux route applies more than one path-mutating filter (e.g.
StripPrefix=1twice), every filter adds a snapshot of the request URL toGATEWAY_ORIGINAL_REQUEST_URL_ATTR, andXForwardedHeadersFilteremitted 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 WebFlux counterpart of gh-4237, fixed separately in #4238 so each module can be reviewed and backported independently.