File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
main/java/org/springframework/web/server/adapter
test/java/org/springframework/web/server/adapter Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2018 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -96,7 +96,7 @@ public ServerHttpRequest apply(ServerHttpRequest request) {
96
96
builder .uri (uri );
97
97
String prefix = getForwardedPrefix (request );
98
98
if (prefix != null ) {
99
- builder .path (prefix + uri .getPath ());
99
+ builder .path (prefix + uri .getRawPath ());
100
100
builder .contextPath (prefix );
101
101
}
102
102
}
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2018 the original author or authors.
2
+ * Copyright 2002-2019 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -90,6 +90,22 @@ public void xForwardedPrefix() throws Exception {
90
90
assertForwardedHeadersRemoved (request );
91
91
}
92
92
93
+ @ Test // gh-23305
94
+ public void xForwardedPrefixShouldNotLeadToDecodedPath () throws Exception {
95
+ HttpHeaders headers = new HttpHeaders ();
96
+ headers .add ("X-Forwarded-Prefix" , "/prefix" );
97
+ ServerHttpRequest request = MockServerHttpRequest
98
+ .method (HttpMethod .GET , new URI ("https://example.com/a%20b?q=a%2Bb" ))
99
+ .headers (headers )
100
+ .build ();
101
+
102
+ request = this .requestMutator .apply (request );
103
+
104
+ assertEquals (new URI ("https://example.com/prefix/a%20b?q=a%2Bb" ), request .getURI ());
105
+ assertEquals ("/prefix/a%20b" , request .getPath ().value ());
106
+ assertForwardedHeadersRemoved (request );
107
+ }
108
+
93
109
@ Test
94
110
public void xForwardedPrefixTrailingSlash () throws Exception {
95
111
HttpHeaders headers = new HttpHeaders ();
You can’t perform that action at this time.
0 commit comments