#170 - LinkBuilder takes X-Forwarded-Port header into account if present.
ControllerLinkBuilder now inspects the X-Forwarded-Port and uses that if present. If an X-Forwarded-Host header doesn't contain a :, we now also reset the port to prevent the local one from leaking into links generated.
This commit is contained in:
committed by
Oliver Gierke
parent
eafbda0c8a
commit
2c6fa4d1b3
@@ -174,13 +174,13 @@ public class ControllerLinkBuilder extends LinkBuilderSupport<ControllerLinkBuil
|
||||
builder.scheme("https");
|
||||
}
|
||||
|
||||
String header = request.getHeader("X-Forwarded-Host");
|
||||
String host = request.getHeader("X-Forwarded-Host");
|
||||
|
||||
if (!StringUtils.hasText(header)) {
|
||||
if (!StringUtils.hasText(host)) {
|
||||
return builder;
|
||||
}
|
||||
|
||||
String[] hosts = StringUtils.commaDelimitedListToStringArray(header);
|
||||
String[] hosts = StringUtils.commaDelimitedListToStringArray(host);
|
||||
String hostToUse = hosts[0];
|
||||
|
||||
if (hostToUse.contains(":")) {
|
||||
@@ -192,6 +192,13 @@ public class ControllerLinkBuilder extends LinkBuilderSupport<ControllerLinkBuil
|
||||
|
||||
} else {
|
||||
builder.host(hostToUse);
|
||||
builder.port(-1); // reset port if it was forwarded from default port
|
||||
}
|
||||
|
||||
String port = request.getHeader("X-Forwarded-Port");
|
||||
|
||||
if (StringUtils.hasText(port)) {
|
||||
builder.port(Integer.parseInt(port));
|
||||
}
|
||||
|
||||
return builder;
|
||||
|
||||
Reference in New Issue
Block a user