Polish "Add configuration property for Tomcat's rejectIllegalHeader"

See gh-26311
pull/26879/head
Stephane Nicoll 4 years ago
parent e5a539d80e
commit d847f4c69e

@ -409,6 +409,11 @@ public class ServerProperties {
*/ */
private Duration connectionTimeout; private Duration connectionTimeout;
/**
* Whether to reject requests with illegal header names or values.
*/
private boolean rejectIllegalHeader = true;
/** /**
* Static resource configuration. * Static resource configuration.
*/ */
@ -424,11 +429,6 @@ public class ServerProperties {
*/ */
private final Remoteip remoteip = new Remoteip(); private final Remoteip remoteip = new Remoteip();
/**
* reject illegal header setting.
*/
private Boolean rejectIllegalHeader;
public DataSize getMaxHttpFormPostSize() { public DataSize getMaxHttpFormPostSize() {
return this.maxHttpFormPostSize; return this.maxHttpFormPostSize;
} }
@ -565,6 +565,14 @@ public class ServerProperties {
this.connectionTimeout = connectionTimeout; this.connectionTimeout = connectionTimeout;
} }
public boolean isRejectIllegalHeader() {
return this.rejectIllegalHeader;
}
public void setRejectIllegalHeader(boolean rejectIllegalHeader) {
this.rejectIllegalHeader = rejectIllegalHeader;
}
public Resource getResource() { public Resource getResource() {
return this.resource; return this.resource;
} }
@ -577,14 +585,6 @@ public class ServerProperties {
return this.remoteip; return this.remoteip;
} }
public Boolean getRejectIllegalHeader() {
return this.rejectIllegalHeader;
}
public void setRejectIllegalHeader(Boolean rejectIllegalHeader) {
this.rejectIllegalHeader = rejectIllegalHeader;
}
/** /**
* Tomcat access log properties. * Tomcat access log properties.
*/ */

@ -117,7 +117,7 @@ public class TomcatWebServerFactoryCustomizer
.to((relaxedChars) -> customizeRelaxedPathChars(factory, relaxedChars)); .to((relaxedChars) -> customizeRelaxedPathChars(factory, relaxedChars));
propertyMapper.from(tomcatProperties::getRelaxedQueryChars).as(this::joinCharacters).whenHasText() propertyMapper.from(tomcatProperties::getRelaxedQueryChars).as(this::joinCharacters).whenHasText()
.to((relaxedChars) -> customizeRelaxedQueryChars(factory, relaxedChars)); .to((relaxedChars) -> customizeRelaxedQueryChars(factory, relaxedChars));
propertyMapper.from(tomcatProperties::getRejectIllegalHeader).whenNonNull() propertyMapper.from(tomcatProperties::isRejectIllegalHeader)
.to((rejectIllegalHeader) -> customizeRejectIllegalHeader(factory, rejectIllegalHeader)); .to((rejectIllegalHeader) -> customizeRejectIllegalHeader(factory, rejectIllegalHeader));
customizeStaticResources(factory); customizeStaticResources(factory);
customizeErrorReportValve(properties.getError(), factory); customizeErrorReportValve(properties.getError(), factory);

@ -130,7 +130,7 @@ class ServerPropertiesTests {
map.put("server.tomcat.remoteip.protocol-header", "X-Forwarded-Protocol"); map.put("server.tomcat.remoteip.protocol-header", "X-Forwarded-Protocol");
map.put("server.tomcat.remoteip.remote-ip-header", "Remote-Ip"); map.put("server.tomcat.remoteip.remote-ip-header", "Remote-Ip");
map.put("server.tomcat.remoteip.internal-proxies", "10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"); map.put("server.tomcat.remoteip.internal-proxies", "10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");
map.put("server.tomcat.reject-illegal-header", "true"); map.put("server.tomcat.reject-illegal-header", "false");
map.put("server.tomcat.background-processor-delay", "10"); map.put("server.tomcat.background-processor-delay", "10");
map.put("server.tomcat.relaxed-path-chars", "|,<"); map.put("server.tomcat.relaxed-path-chars", "|,<");
map.put("server.tomcat.relaxed-query-chars", "^ , | "); map.put("server.tomcat.relaxed-query-chars", "^ , | ");
@ -153,7 +153,7 @@ class ServerPropertiesTests {
assertThat(tomcat.getRemoteip().getRemoteIpHeader()).isEqualTo("Remote-Ip"); assertThat(tomcat.getRemoteip().getRemoteIpHeader()).isEqualTo("Remote-Ip");
assertThat(tomcat.getRemoteip().getProtocolHeader()).isEqualTo("X-Forwarded-Protocol"); assertThat(tomcat.getRemoteip().getProtocolHeader()).isEqualTo("X-Forwarded-Protocol");
assertThat(tomcat.getRemoteip().getInternalProxies()).isEqualTo("10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"); assertThat(tomcat.getRemoteip().getInternalProxies()).isEqualTo("10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}");
assertThat(tomcat.getRejectIllegalHeader()).isTrue(); assertThat(tomcat.isRejectIllegalHeader()).isFalse();
assertThat(tomcat.getBackgroundProcessorDelay()).hasSeconds(10); assertThat(tomcat.getBackgroundProcessorDelay()).hasSeconds(10);
assertThat(tomcat.getRelaxedPathChars()).containsExactly('|', '<'); assertThat(tomcat.getRelaxedPathChars()).containsExactly('|', '<');
assertThat(tomcat.getRelaxedQueryChars()).containsExactly('^', '|'); assertThat(tomcat.getRelaxedQueryChars()).containsExactly('^', '|');
@ -408,8 +408,9 @@ class ServerPropertiesTests {
} }
@Test @Test
void tomcatRejectIllegalHeaderDefaultsToNull() { void tomcatRejectIllegalHeaderMatchesProtocolDefault() throws Exception {
assertThat(this.properties.getTomcat().getRejectIllegalHeader()).isNull(); assertThat(getDefaultProtocol()).hasFieldOrPropertyWithValue("rejectIllegalHeader",
this.properties.getTomcat().isRejectIllegalHeader());
} }
@Test @Test

Loading…
Cancel
Save