Skip to content

Commit f5f3d7c

Browse files
committed
Polish "Add configuration property for RemoteIpValve's trusted proxies"
See gh-31576
1 parent 7d61295 commit f5f3d7c

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ServerProperties.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -966,11 +966,6 @@ public static class Remoteip {
966966
+ "172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3}|" //
967967
+ "0:0:0:0:0:0:0:1|::1";
968968

969-
/**
970-
* Regular expression defining proxies that are trusted when they appear in the remoteIpHeader header.
971-
*/
972-
private String trustedProxies;
973-
974969
/**
975970
* Header that holds the incoming protocol, usually named "X-Forwarded-Proto".
976971
*/
@@ -998,6 +993,12 @@ public static class Remoteip {
998993
*/
999994
private String remoteIpHeader;
1000995

996+
/**
997+
* Regular expression defining proxies that are trusted when they appear in
998+
* the "remote-ip-header" header.
999+
*/
1000+
private String trustedProxies;
1001+
10011002
public String getInternalProxies() {
10021003
return this.internalProxies;
10031004
}
@@ -1047,12 +1048,13 @@ public void setRemoteIpHeader(String remoteIpHeader) {
10471048
}
10481049

10491050
public String getTrustedProxies() {
1050-
return trustedProxies;
1051+
return this.trustedProxies;
10511052
}
10521053

10531054
public void setTrustedProxies(String trustedProxies) {
10541055
this.trustedProxies = trustedProxies;
10551056
}
1057+
10561058
}
10571059

10581060
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ private void customizeRemoteIpValve(ConfigurableTomcatWebServerFactory factory)
227227
if (StringUtils.hasLength(remoteIpHeader)) {
228228
valve.setRemoteIpHeader(remoteIpHeader);
229229
}
230+
valve.setTrustedProxies(remoteIpProperties.getTrustedProxies());
230231
// The internal proxies default to a list of "safe" internal IP addresses
231232
valve.setInternalProxies(remoteIpProperties.getInternalProxies());
232-
valve.setTrustedProxies(remoteIpProperties.getTrustedProxies());
233233
try {
234234
valve.setHostHeader(remoteIpProperties.getHostHeader());
235235
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/embedded/TomcatWebServerFactoryCustomizerTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ void customRemoteIpValve() {
224224
bind("server.tomcat.remoteip.remote-ip-header=x-my-remote-ip-header",
225225
"server.tomcat.remoteip.protocol-header=x-my-protocol-header",
226226
"server.tomcat.remoteip.internal-proxies=192.168.0.1",
227-
"server.tomcat.remoteip.trusted-proxies=proxy1|proxy2",
228227
"server.tomcat.remoteip.host-header=x-my-forward-host",
229228
"server.tomcat.remoteip.port-header=x-my-forward-port",
230-
"server.tomcat.remoteip.protocol-header-https-value=On");
229+
"server.tomcat.remoteip.protocol-header-https-value=On",
230+
"server.tomcat.remoteip.trusted-proxies=proxy1|proxy2");
231231
TomcatServletWebServerFactory factory = customizeAndGetFactory();
232232
assertThat(factory.getEngineValves()).hasSize(1);
233233
Valve valve = factory.getEngineValves().iterator().next();

0 commit comments

Comments
 (0)