Improve handling of reserved characters in MetaInfResourceManager
Previously, MetaInfResourceManager that we use with Undertow to serve static resources from jar's META-INF/resources did not correctly handle characters in the path that should be percent-encoded when used in a URL. This commit updates MetaInfResourceManager to encode the path before it is used to create a URL. Prior to this encoding, encoded slashes (%2F) are decoded as, unlike other encoded characters in the request's URL, encoded slashes are not decoded prior to calling the ResourceManager. Fixes gh-17853
This commit is contained in:
@@ -90,6 +90,10 @@ class ApplicationBuilder {
|
||||
resourcesJarStream.putNextEntry(new ZipEntry("META-INF/resources/nested-meta-inf-resource.txt"));
|
||||
resourcesJarStream.write("nested".getBytes());
|
||||
resourcesJarStream.closeEntry();
|
||||
resourcesJarStream.putNextEntry(
|
||||
new ZipEntry("META-INF/resources/nested-reserved-!#$%&()*+,:=?@[]-meta-inf-resource.txt"));
|
||||
resourcesJarStream.write("encoded-name".getBytes());
|
||||
resourcesJarStream.closeEntry();
|
||||
return resourcesJar;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,15 @@ public class EmbeddedServletContainerJarDevelopmentIntegrationTests
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metaInfResourceFromDependencyWithNameThatContainsReservedCharactersIsAvailableViaHttp() {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity(
|
||||
"/nested-reserved-%21%23%24%25%26%28%29%2A%2B%2C%3A%3D%3F%40%5B%5D-meta-inf-resource.txt",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).isEqualTo("encoded-name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metaInfResourceFromDependencyIsAvailableViaServletContext() {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/servletContext?/nested-meta-inf-resource.txt",
|
||||
|
||||
@@ -54,6 +54,15 @@ public class EmbeddedServletContainerJarPackagingIntegrationTests
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedMetaInfResourceWithNameThatContainsReservedCharactersIsAvailableViaHttp() {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity(
|
||||
"/nested-reserved-%21%23%24%25%26%28%29%2A%2B%2C%3A%3D%3F%40%5B%5D-meta-inf-resource.txt",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).isEqualTo("encoded-name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedMetaInfResourceIsAvailableViaServletContext() {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/servletContext?/nested-meta-inf-resource.txt",
|
||||
|
||||
@@ -60,6 +60,15 @@ public class EmbeddedServletContainerWarDevelopmentIntegrationTests
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metaInfResourceFromDependencyWithNameThatContainsReservedCharactersIsAvailableViaHttp() {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity(
|
||||
"/nested-reserved-%21%23%24%25%26%28%29%2A%2B%2C%3A%3D%3F%40%5B%5D-meta-inf-resource.txt",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).isEqualTo("encoded-name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metaInfResourceFromDependencyIsAvailableViaServletContext() {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/servletContext?/nested-meta-inf-resource.txt",
|
||||
|
||||
@@ -60,6 +60,15 @@ public class EmbeddedServletContainerWarPackagingIntegrationTests
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedMetaInfResourceWithNameThatContainsReservedCharactersIsAvailableViaHttp() {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity(
|
||||
"/nested-reserved-%21%23%24%25%26%28%29%2A%2B%2C%3A%3D%3F%40%5B%5D-meta-inf-resource.txt",
|
||||
String.class);
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(entity.getBody()).isEqualTo("encoded-name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedMetaInfResourceIsAvailableViaServletContext() {
|
||||
ResponseEntity<String> entity = this.rest.getForEntity("/servletContext?/nested-meta-inf-resource.txt",
|
||||
|
||||
Reference in New Issue
Block a user