Skip to content

Commit 01ba0f7

Browse files
committed
Make RemoteIpValve's protocolHeaderHttpsValue configurable via the env
Closes gh-3289
1 parent 5f2ffdb commit 01ba0f7

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ public static class Tomcat {
271271
*/
272272
private String protocolHeader;
273273

274+
/**
275+
* Value of the protocol header that indicates that the incoming request uses SSL.
276+
*/
277+
private String protocolHeaderHttpsValue = "https";
278+
274279
/**
275280
* Name of the HTTP header used to override the original port value.
276281
*/
@@ -400,6 +405,14 @@ public void setProtocolHeader(String protocolHeader) {
400405
this.protocolHeader = protocolHeader;
401406
}
402407

408+
public String getProtocolHeaderHttpsValue() {
409+
return this.protocolHeaderHttpsValue;
410+
}
411+
412+
public void setProtocolHeaderHttpsValue(String protocolHeaderHttpsValue) {
413+
this.protocolHeaderHttpsValue = protocolHeaderHttpsValue;
414+
}
415+
403416
public String getPortHeader() {
404417
return this.portHeader;
405418
}
@@ -445,6 +458,7 @@ public void customize(Context context) {
445458
valve.setProtocolHeader(protocolHeader);
446459
valve.setInternalProxies(getInternalProxies());
447460
valve.setPortHeader(getPortHeader());
461+
valve.setProtocolHeaderHttpsValue(getProtocolHeaderHttpsValue());
448462
factory.addContextValves(valve);
449463
}
450464

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ServerPropertiesTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ public void defaultTomcatRemoteIpValve() throws Exception {
165165
assertThat(valve, instanceOf(RemoteIpValve.class));
166166
RemoteIpValve remoteIpValve = (RemoteIpValve) valve;
167167
assertEquals("x-forwarded-proto", remoteIpValve.getProtocolHeader());
168+
assertEquals("https", remoteIpValve.getProtocolHeaderHttpsValue());
168169
assertEquals("x-forwarded-for", remoteIpValve.getRemoteIpHeader());
169170

170171
String expectedInternalProxies = "10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|" // 10/8
@@ -182,6 +183,7 @@ public void customTomcatRemoteIpValve() throws Exception {
182183
map.put("server.tomcat.protocol_header", "x-my-protocol-header");
183184
map.put("server.tomcat.internal_proxies", "192.168.0.1");
184185
map.put("server.tomcat.port-header", "x-my-forward-port");
186+
map.put("server.tomcat.protocol-header-https-value", "On");
185187
bindProperties(map);
186188

187189
TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory();
@@ -192,6 +194,7 @@ public void customTomcatRemoteIpValve() throws Exception {
192194
assertThat(valve, instanceOf(RemoteIpValve.class));
193195
RemoteIpValve remoteIpValve = (RemoteIpValve) valve;
194196
assertEquals("x-my-protocol-header", remoteIpValve.getProtocolHeader());
197+
assertEquals("On", remoteIpValve.getProtocolHeaderHttpsValue());
195198
assertEquals("x-my-remote-ip-header", remoteIpValve.getRemoteIpHeader());
196199
assertEquals("x-my-forward-port", remoteIpValve.getPortHeader());
197200
assertEquals("192.168.0.1", remoteIpValve.getInternalProxies());

spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ content into your application; rather pick only the properties that you need.
8181
169\\.254\\.\\d{1,3}\\.\\d{1,3}|\\
8282
127\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3} # regular expression matching trusted IP addresses
8383
server.tomcat.protocol-header=x-forwarded-proto # front end proxy forward header
84+
server.tomcat.protocol-header-https-value=https # value of the protocol header that indicates that the incoming request uses SSL
8485
server.tomcat.port-header= # front end proxy port header
8586
server.tomcat.remote-ip-header=x-forwarded-for
8687
server.tomcat.basedir=/tmp # base dir (usually not needed, defaults to tmp)

0 commit comments

Comments
 (0)