File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed
main/java/org/springframework/web/util
test/java/org/springframework/web/util Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -754,8 +754,7 @@ UriComponentsBuilder adaptFromForwardedHeaders(HttpHeaders headers) {
754
754
try {
755
755
String forwardedHeader = headers .getFirst ("Forwarded" );
756
756
if (StringUtils .hasText (forwardedHeader )) {
757
- String forwardedToUse = StringUtils .tokenizeToStringArray (forwardedHeader , "," )[0 ];
758
- Matcher matcher = FORWARDED_PROTO_PATTERN .matcher (forwardedToUse );
757
+ Matcher matcher = FORWARDED_PROTO_PATTERN .matcher (forwardedHeader );
759
758
if (matcher .find ()) {
760
759
scheme (matcher .group (1 ).trim ());
761
760
port (null );
@@ -764,7 +763,7 @@ else if (isForwardedSslOn(headers)) {
764
763
scheme ("https" );
765
764
port (null );
766
765
}
767
- matcher = FORWARDED_HOST_PATTERN .matcher (forwardedToUse );
766
+ matcher = FORWARDED_HOST_PATTERN .matcher (forwardedHeader );
768
767
if (matcher .find ()) {
769
768
adaptForwardedHost (matcher .group (1 ).trim ());
770
769
}
Original file line number Diff line number Diff line change @@ -1114,6 +1114,26 @@ void fromHttpRequestForwardedHeaderWithProtoAndServerPort() {
1114
1114
assertThat (result .toUriString ()).isEqualTo ("https://example.com/rest/mobile/users/1" );
1115
1115
}
1116
1116
1117
+ @ Test // gh-25737
1118
+ void fromHttpRequestForwardedHeaderComma () {
1119
+ MockHttpServletRequest request = new MockHttpServletRequest ();
1120
+ request .addHeader ("Forwarded" , "for=192.0.2.0,for=192.0.2.1;proto=https;host=192.0.2.3:9090" );
1121
+ request .setScheme ("http" );
1122
+ request .setServerPort (8080 );
1123
+ request .setServerName ("example.com" );
1124
+ request .setRequestURI ("/rest/mobile/users/1" );
1125
+
1126
+ HttpRequest httpRequest = new ServletServerHttpRequest (request );
1127
+ UriComponents result = UriComponentsBuilder .fromHttpRequest (httpRequest ).build ();
1128
+
1129
+ assertThat (result .getScheme ()).isEqualTo ("https" );
1130
+ assertThat (result .getHost ()).isEqualTo ("192.0.2.3" );
1131
+ assertThat (result .getPath ()).isEqualTo ("/rest/mobile/users/1" );
1132
+ assertThat (result .getPort ()).isEqualTo (9090 );
1133
+ assertThat (result .toUriString ()).isEqualTo ("https://192.0.2.3:9090/rest/mobile/users/1" );
1134
+ }
1135
+
1136
+
1117
1137
@ Test // SPR-16364
1118
1138
void uriComponentsNotEqualAfterNormalization () {
1119
1139
UriComponents uri1 = UriComponentsBuilder .fromUriString ("http://test.com" ).build ().normalize ();
You can’t perform that action at this time.
0 commit comments