diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceHandlerUtils.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceHandlerUtils.java index e2687b2909f..277609e011f 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceHandlerUtils.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceHandlerUtils.java @@ -74,9 +74,6 @@ public abstract class ResourceHandlerUtils { } else if (location instanceof ContextResource contextResource) { path = contextResource.getPathWithinContext(); - Assert.isTrue(!"/".equals(path), - () -> "Resource location '" + location + "' is considered unsafe " + - "and cannot be used as it provides access to the root servlet context."); } else if (location instanceof UrlResource) { path = location.getURL().toExternalForm(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceHandlerUtilsTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceHandlerUtilsTests.java index 3b3c0059c71..56836b1057c 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceHandlerUtilsTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/resource/ResourceHandlerUtilsTests.java @@ -82,13 +82,6 @@ class ResourceHandlerUtilsTests { .withMessageContaining("is considered unsafe"); } - @Test - void assertResourceLocationShouldRejectUnsafeContextResource() { - assertThatIllegalArgumentException().isThrownBy(() -> - ResourceHandlerUtils.assertResourceLocation(new TestContextResource("/"))) - .withMessageContaining("is considered unsafe"); - } - private static class TestContextResource implements ContextResource { private final String path; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHandlerUtils.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHandlerUtils.java index 214f80fc5f1..367654fa7d5 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHandlerUtils.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHandlerUtils.java @@ -75,9 +75,6 @@ public abstract class ResourceHandlerUtils { } else if (location instanceof ContextResource contextResource) { path = contextResource.getPathWithinContext(); - Assert.isTrue(!"/".equals(path), - () -> "Resource location '" + location + "' is considered unsafe " + - "and cannot be used as it provides access to the root servlet context."); } else if (location instanceof UrlResource) { path = location.getURL().toExternalForm(); diff --git a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHandlerUtilsTests.java b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHandlerUtilsTests.java index 84c72de129b..0f1c9c5ed44 100644 --- a/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHandlerUtilsTests.java +++ b/spring-webmvc/src/test/java/org/springframework/web/servlet/resource/ResourceHandlerUtilsTests.java @@ -77,11 +77,4 @@ class ResourceHandlerUtilsTests { .withMessageContaining("is considered unsafe"); } - @Test - void assertResourceLocationShouldRejectUnsafeContextResource() { - assertThatIllegalArgumentException().isThrownBy(() -> - ResourceHandlerUtils.assertResourceLocation(new ServletContextResource(new MockServletContext(), "/"))) - .withMessageContaining("is considered unsafe"); - } - }