Merge pull request #23305' from AndreasKl/fowarded-prefix-causes-invalid-path into 5.1.x

This commit is contained in:
Rossen Stoyanchev 2019-07-19 10:44:42 +01:00
commit a244675630
2 changed files with 19 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -96,7 +96,7 @@ public class ForwardedHeaderTransformer implements Function<ServerHttpRequest, S
builder.uri(uri);
String prefix = getForwardedPrefix(request);
if (prefix != null) {
builder.path(prefix + uri.getPath());
builder.path(prefix + uri.getRawPath());
builder.contextPath(prefix);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -90,6 +90,22 @@ public class ForwardedHeaderTransformerTests {
assertForwardedHeadersRemoved(request);
}
@Test // gh-23305
public void xForwardedPrefixShouldNotLeadToDecodedPath() throws Exception {
HttpHeaders headers = new HttpHeaders();
headers.add("X-Forwarded-Prefix", "/prefix");
ServerHttpRequest request = MockServerHttpRequest
.method(HttpMethod.GET, new URI("https://example.com/a%20b?q=a%2Bb"))
.headers(headers)
.build();
request = this.requestMutator.apply(request);
assertEquals(new URI("https://example.com/prefix/a%20b?q=a%2Bb"), request.getURI());
assertEquals("/prefix/a%20b", request.getPath().value());
assertForwardedHeadersRemoved(request);
}
@Test
public void xForwardedPrefixTrailingSlash() throws Exception {
HttpHeaders headers = new HttpHeaders();