Skip to content

Commit

Permalink
Merge pull request spring-projects#23305' from AndreasKl/fowarded-pre…
Browse files Browse the repository at this point in the history
…fix-causes-invalid-path into 5.1.x
  • Loading branch information
rstoyanchev committed Jul 19, 2019
2 parents ab2fcbd + 4791b72 commit f70bf46
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -96,7 +96,7 @@ public ServerHttpRequest apply(ServerHttpRequest request) {
builder.uri(uri);
String prefix = getForwardedPrefix(request);
if (prefix != null) {
builder.path(prefix + uri.getPath());
builder.path(prefix + uri.getRawPath());
builder.contextPath(prefix);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -90,6 +90,22 @@ public void xForwardedPrefix() throws Exception {
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();
Expand Down

0 comments on commit f70bf46

Please sign in to comment.