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 @@ -806,8 +806,7 @@ UriComponentsBuilder adaptFromForwardedHeaders(HttpHeaders headers) {
806
806
try {
807
807
String forwardedHeader = headers .getFirst ("Forwarded" );
808
808
if (StringUtils .hasText (forwardedHeader )) {
809
- String forwardedToUse = StringUtils .tokenizeToStringArray (forwardedHeader , "," )[0 ];
810
- Matcher matcher = FORWARDED_PROTO_PATTERN .matcher (forwardedToUse );
809
+ Matcher matcher = FORWARDED_PROTO_PATTERN .matcher (forwardedHeader );
811
810
if (matcher .find ()) {
812
811
scheme (matcher .group (1 ).trim ());
813
812
port (null );
@@ -816,7 +815,7 @@ else if (isForwardedSslOn(headers)) {
816
815
scheme ("https" );
817
816
port (null );
818
817
}
819
- matcher = FORWARDED_HOST_PATTERN .matcher (forwardedToUse );
818
+ matcher = FORWARDED_HOST_PATTERN .matcher (forwardedHeader );
820
819
if (matcher .find ()) {
821
820
adaptForwardedHost (matcher .group (1 ).trim ());
822
821
}
Original file line number Diff line number Diff line change @@ -1120,6 +1120,26 @@ void fromHttpRequestForwardedHeaderWithProtoAndServerPort() {
1120
1120
assertThat (result .toUriString ()).isEqualTo ("https://example.com/rest/mobile/users/1" );
1121
1121
}
1122
1122
1123
+ @ Test // gh-25737
1124
+ void fromHttpRequestForwardedHeaderComma () {
1125
+ MockHttpServletRequest request = new MockHttpServletRequest ();
1126
+ request .addHeader ("Forwarded" , "for=192.0.2.0,for=192.0.2.1;proto=https;host=192.0.2.3:9090" );
1127
+ request .setScheme ("http" );
1128
+ request .setServerPort (8080 );
1129
+ request .setServerName ("example.com" );
1130
+ request .setRequestURI ("/rest/mobile/users/1" );
1131
+
1132
+ HttpRequest httpRequest = new ServletServerHttpRequest (request );
1133
+ UriComponents result = UriComponentsBuilder .fromHttpRequest (httpRequest ).build ();
1134
+
1135
+ assertThat (result .getScheme ()).isEqualTo ("https" );
1136
+ assertThat (result .getHost ()).isEqualTo ("192.0.2.3" );
1137
+ assertThat (result .getPath ()).isEqualTo ("/rest/mobile/users/1" );
1138
+ assertThat (result .getPort ()).isEqualTo (9090 );
1139
+ assertThat (result .toUriString ()).isEqualTo ("https://192.0.2.3:9090/rest/mobile/users/1" );
1140
+ }
1141
+
1142
+
1123
1143
@ Test // SPR-16364
1124
1144
void uriComponentsNotEqualAfterNormalization () {
1125
1145
UriComponents uri1 = UriComponentsBuilder .fromUriString ("http://test.com" ).build ().normalize ();
You can’t perform that action at this time.
0 commit comments