Fix forwarded host formatting

Follow-up to recent commit
75e2e2c3c7

Closes gh-34253
This commit is contained in:
rstoyanchev
2025-01-28 15:49:26 +00:00
parent 83cdd58ac8
commit f5b5f9a639
3 changed files with 5 additions and 4 deletions

View File

@@ -181,7 +181,8 @@ public abstract class ForwardedHeaderUtils {
String forHeader = headers.getFirst("X-Forwarded-For");
if (StringUtils.hasText(forHeader)) {
String host = StringUtils.tokenizeToStringArray(forHeader, ",")[0];
host = (!host.startsWith("[") && !host.endsWith("]") ? "[" + host + "]" : host);
boolean ipv6 = (host.indexOf(':') != -1);
host = (ipv6 && !host.startsWith("[") && !host.endsWith("]") ? "[" + host + "]" : host);
return InetSocketAddress.createUnresolved(host, port);
}