Skip to content

Commit

Permalink
Do not support relative static resource paths
Browse files Browse the repository at this point in the history
Closes gh-33687
  • Loading branch information
rstoyanchev committed Oct 14, 2024
1 parent e191c34 commit 1a0b577
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static boolean isInvalidPath(String path) {
return true;
}
}
if (path.contains("..") && StringUtils.cleanPath(path).contains("../")) {
if (path.contains("../")) {
if (logger.isWarnEnabled()) {
logger.warn(LogFormatUtils.formatValue(
"Path contains \"../\" after call to StringUtils#cleanPath: [" + path + "]", -1, true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ void resolvePathWithTraversal(HttpMethod method) throws Exception {

testResolvePathWithTraversal(method, "../testsecret/secret.txt");
testResolvePathWithTraversal(method, "test/../../testsecret/secret.txt");
testResolvePathWithTraversal(method, "/testsecret/test/../secret.txt");
testResolvePathWithTraversal(method, ":/../../testsecret/secret.txt");

location = new UrlResource(getClass().getResource("./test/"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static boolean isInvalidPath(String path) {
return true;
}
}
if (path.contains("..") && StringUtils.cleanPath(path).contains("../")) {
if (path.contains("../")) {
if (logger.isWarnEnabled()) {
logger.warn(LogFormatUtils.formatValue(
"Path contains \"../\" after call to StringUtils#cleanPath: [" + path + "]", -1, true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ void shouldRejectInvalidPath() throws Exception {
testInvalidPath("../testsecret/secret.txt");
testInvalidPath("test/../../testsecret/secret.txt");
testInvalidPath(":/../../testsecret/secret.txt");
testInvalidPath("/testsecret/test/../secret.txt");

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

0 comments on commit 1a0b577

Please sign in to comment.