From 5826e5666662c5f44469d73645bb0ea49480505a Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Fri, 23 Feb 2024 15:44:01 +1100 Subject: [PATCH] PR #11433 - fix for symlink loops in Resource.getAllResources Signed-off-by: Lachlan Roberts --- .../org/eclipse/jetty/util/resource/Resource.java | 11 ++++++++++- .../eclipse/jetty/util/resource/PathResourceTest.java | 6 ------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java index c1c6fd7c1ca..cae05a53dfd 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java @@ -405,7 +405,16 @@ public abstract class Resource implements Iterable boolean noDepth = true; for (Iterator i = children.iterator(); noDepth && i.hasNext(); ) - noDepth = !i.next().isDirectory(); + { + Resource resource = i.next(); + if (resource.isDirectory()) + { + // If the directory is a symlink we do not want to go any deeper. + Path resourcePath = resource.getPath(); + if (resourcePath == null || !Files.isSymbolicLink(resourcePath)) + noDepth = false; + } + } if (noDepth) return children; diff --git a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/PathResourceTest.java b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/PathResourceTest.java index b3ea77bb4ee..24f85ac3e89 100644 --- a/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/PathResourceTest.java +++ b/jetty-core/jetty-util/src/test/java/org/eclipse/jetty/util/resource/PathResourceTest.java @@ -27,7 +27,6 @@ import java.nio.file.InvalidPathException; import java.nio.file.Path; import java.util.Collection; import java.util.HashMap; -import java.util.List; import java.util.Map; import org.eclipse.jetty.toolchain.test.FS; @@ -728,11 +727,6 @@ public class PathResourceTest resource.resolve("foo.txt") }; - List actual = allResources.stream() - .map(Resource::getURI) - .map(URI::toASCIIString) - .toList(); - assertThat(allResources, containsInAnyOrder(expected)); } }