Skip to content

Commit 1a0b577

Browse files
committed
Do not support relative static resource paths
Closes gh-33687
1 parent e191c34 commit 1a0b577

File tree

4 files changed

+4
-2
lines changed

4 files changed

+4
-2
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceHandlerUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public static boolean isInvalidPath(String path) {
140140
return true;
141141
}
142142
}
143-
if (path.contains("..") && StringUtils.cleanPath(path).contains("../")) {
143+
if (path.contains("../")) {
144144
if (logger.isWarnEnabled()) {
145145
logger.warn(LogFormatUtils.formatValue(
146146
"Path contains \"../\" after call to StringUtils#cleanPath: [" + path + "]", -1, true));

spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceWebHandlerTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ void resolvePathWithTraversal(HttpMethod method) throws Exception {
687687

688688
testResolvePathWithTraversal(method, "../testsecret/secret.txt");
689689
testResolvePathWithTraversal(method, "test/../../testsecret/secret.txt");
690+
testResolvePathWithTraversal(method, "/testsecret/test/../secret.txt");
690691
testResolvePathWithTraversal(method, ":/../../testsecret/secret.txt");
691692

692693
location = new UrlResource(getClass().getResource("./test/"));

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHandlerUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public static boolean isInvalidPath(String path) {
140140
return true;
141141
}
142142
}
143-
if (path.contains("..") && StringUtils.cleanPath(path).contains("../")) {
143+
if (path.contains("../")) {
144144
if (logger.isWarnEnabled()) {
145145
logger.warn(LogFormatUtils.formatValue(
146146
"Path contains \"../\" after call to StringUtils#cleanPath: [" + path + "]", -1, true));

spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandlerTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@ void shouldRejectInvalidPath() throws Exception {
643643
testInvalidPath("../testsecret/secret.txt");
644644
testInvalidPath("test/../../testsecret/secret.txt");
645645
testInvalidPath(":/../../testsecret/secret.txt");
646+
testInvalidPath("/testsecret/test/../secret.txt");
646647

647648
Resource location = new UrlResource(ResourceHttpRequestHandlerTests.class.getResource("./test/"));
648649
this.handler.setLocations(List.of(location));

0 commit comments

Comments
 (0)