Skip to content

Commit c804299

Browse files
committed
Prevent Undertow from exposing classpath files
Update `UndertowEmbeddedServletContainerFactory` so that the `ClassPathResourceManager` is no longer registered by default. Prior to this commit the resource manager would be registered whenever a valid document root could not be found. This had the effect of exposing all classpath files. Fixes gh-4015
1 parent 5664322 commit c804299

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

spring-boot/src/main/java/org/springframework/boot/context/embedded/undertow/UndertowEmbeddedServletContainerFactory.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
import io.undertow.Undertow;
5757
import io.undertow.Undertow.Builder;
5858
import io.undertow.UndertowMessages;
59-
import io.undertow.server.handlers.resource.ClassPathResourceManager;
6059
import io.undertow.server.handlers.resource.FileResourceManager;
6160
import io.undertow.server.handlers.resource.Resource;
6261
import io.undertow.server.handlers.resource.ResourceChangeListener;
@@ -370,10 +369,7 @@ private ResourceManager getDocumentRootResourceManager() {
370369
if (root != null && root.isFile()) {
371370
return new JarResourcemanager(root);
372371
}
373-
if (this.resourceLoader != null) {
374-
return new ClassPathResourceManager(this.resourceLoader.getClassLoader(), "");
375-
}
376-
return new ClassPathResourceManager(getClass().getClassLoader(), "");
372+
return ResourceManager.EMPTY_RESOURCE_MANAGER;
377373
}
378374

379375
private void configureErrorPages(DeploymentInfo servletBuilder) {

spring-boot/src/test/java/org/springframework/boot/context/embedded/AbstractEmbeddedServletContainerFactoryTests.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,17 @@ public void sslWantsClientAuthenticationSucceedsWithoutClientCertificate()
482482
equalTo("test"));
483483
}
484484

485+
@Test
486+
public void cannotReadClassPathFiles() throws Exception {
487+
AbstractEmbeddedServletContainerFactory factory = getFactory();
488+
this.container = factory
489+
.getEmbeddedServletContainer(exampleServletRegistration());
490+
this.container.start();
491+
ClientHttpResponse response = getClientResponse(
492+
getLocalUrl("/org/springframework/boot/SpringApplication.class"));
493+
assertThat(response.getStatusCode(), equalTo(HttpStatus.NOT_FOUND));
494+
}
495+
485496
private Ssl getSsl(ClientAuth clientAuth, String keyPassword, String keyStore) {
486497
return getSsl(clientAuth, keyPassword, keyStore, null);
487498
}

0 commit comments

Comments
 (0)