Fix NumberFormatException with X-Forwarded-Host
This commit fixes `NumberFormatException`s that were thrown when parsing IPv6 host values in `X-Forwarded-Host` request headers. Issue: SPR-14761
This commit is contained in:
@@ -51,6 +51,7 @@ import org.springframework.web.util.HierarchicalUriComponents.PathComponent;
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Phillip Webb
|
||||
* @author Oliver Gierke
|
||||
* @author Brian Clozel
|
||||
* @since 3.1
|
||||
* @see #newInstance()
|
||||
* @see #fromPath(String)
|
||||
@@ -687,10 +688,10 @@ public class UriComponentsBuilder implements Cloneable {
|
||||
String hostHeader = headers.getFirst("X-Forwarded-Host");
|
||||
if (StringUtils.hasText(hostHeader)) {
|
||||
String hostToUse = StringUtils.tokenizeToStringArray(hostHeader, ",")[0];
|
||||
String[] hostAndPort = StringUtils.split(hostToUse, ":");
|
||||
if (hostAndPort != null) {
|
||||
host(hostAndPort[0]);
|
||||
port(Integer.parseInt(hostAndPort[1]));
|
||||
int portSeparatorIdx = hostToUse.lastIndexOf(":");
|
||||
if (portSeparatorIdx > hostToUse.lastIndexOf("]")) {
|
||||
host(hostToUse.substring(0, portSeparatorIdx));
|
||||
port(Integer.parseInt(hostToUse.substring(portSeparatorIdx + 1)));
|
||||
}
|
||||
else {
|
||||
host(hostToUse);
|
||||
|
||||
Reference in New Issue
Block a user