ForwardedHeaderTransformer handles encoding correctly
Issue: SPR-17525
This commit is contained in:
@@ -84,7 +84,7 @@ public class ForwardedHeaderFilter implements WebFilter {
|
||||
return chain.filter(withoutForwardHeaders);
|
||||
}
|
||||
else {
|
||||
URI uri = UriComponentsBuilder.fromHttpRequest(exchange.getRequest()).build().toUri();
|
||||
URI uri = UriComponentsBuilder.fromHttpRequest(exchange.getRequest()).build(true).toUri();
|
||||
String prefix = getForwardedPrefix(exchange.getRequest().getHeaders());
|
||||
|
||||
ServerWebExchange withChangedUri = exchange.mutate()
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.junit.Test;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import org.springframework.mock.web.test.server.MockServerWebExchange;
|
||||
@@ -113,6 +114,18 @@ public class ForwardedHeaderFilterTests {
|
||||
assertEquals(new URI("http://example.com/prefix/path"), uri);
|
||||
}
|
||||
|
||||
@Test // SPR-17525
|
||||
public void shouldNotDoubleEncode() throws Exception {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest
|
||||
.method(HttpMethod.GET, new URI ("http://example.com/a%20b?q=a%2Bb"))
|
||||
.header("Forwarded", "host=84.198.58.199;proto=https"));
|
||||
|
||||
this.filter.filter(exchange, this.filterChain).block(Duration.ZERO);
|
||||
|
||||
URI uri = this.filterChain.uri;
|
||||
assertEquals(new URI("https://84.198.58.199/a%20b?q=a%2Bb"), uri);
|
||||
}
|
||||
|
||||
|
||||
private static class TestWebFilterChain implements WebFilterChain {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user