Skip to content

Commit

Permalink
Prevent Undertow from exposing classpath files
Browse files Browse the repository at this point in the history
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 spring-projectsgh-4015
  • Loading branch information
philwebb committed Oct 15, 2015
1 parent 5664322 commit c804299
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import io.undertow.Undertow;
import io.undertow.Undertow.Builder;
import io.undertow.UndertowMessages;
import io.undertow.server.handlers.resource.ClassPathResourceManager;
import io.undertow.server.handlers.resource.FileResourceManager;
import io.undertow.server.handlers.resource.Resource;
import io.undertow.server.handlers.resource.ResourceChangeListener;
Expand Down Expand Up @@ -370,10 +369,7 @@ private ResourceManager getDocumentRootResourceManager() {
if (root != null && root.isFile()) {
return new JarResourcemanager(root);
}
if (this.resourceLoader != null) {
return new ClassPathResourceManager(this.resourceLoader.getClassLoader(), "");
}
return new ClassPathResourceManager(getClass().getClassLoader(), "");
return ResourceManager.EMPTY_RESOURCE_MANAGER;
}

private void configureErrorPages(DeploymentInfo servletBuilder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,17 @@ public void sslWantsClientAuthenticationSucceedsWithoutClientCertificate()
equalTo("test"));
}

@Test
public void cannotReadClassPathFiles() throws Exception {
AbstractEmbeddedServletContainerFactory factory = getFactory();
this.container = factory
.getEmbeddedServletContainer(exampleServletRegistration());
this.container.start();
ClientHttpResponse response = getClientResponse(
getLocalUrl("/org/springframework/boot/SpringApplication.class"));
assertThat(response.getStatusCode(), equalTo(HttpStatus.NOT_FOUND));
}

private Ssl getSsl(ClientAuth clientAuth, String keyPassword, String keyStore) {
return getSsl(clientAuth, keyPassword, keyStore, null);
}
Expand Down

0 comments on commit c804299

Please sign in to comment.