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 2e95c58fd5b..e2687b2909f 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 @@ -19,7 +19,6 @@ package org.springframework.web.reactive.resource; import java.io.IOException; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; -import java.util.Locale; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -69,17 +68,15 @@ public abstract class ResourceHandlerUtils { } else if (location instanceof ClassPathResource classPathResource) { path = classPathResource.getPath(); - if (path.isEmpty() || "/".equals(path)) { - logger.warn("Resource location '" + location + "' is considered unsafe " + - "and should not be used as it provides access to the entire classpath."); - } + Assert.isTrue(!path.isEmpty() && !"/".equals(path), + () -> "Resource location '" + location + "' is considered unsafe " + + "and cannot be used as it provides access to the entire classpath."); } else if (location instanceof ContextResource contextResource) { path = contextResource.getPathWithinContext(); - if ("/".equals(path)) { - logger.warn("Resource location '" + location + "' is considered unsafe " + - "and should not be used as it provides access to the root servlet context."); - } + 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(); @@ -176,7 +173,6 @@ public abstract class ResourceHandlerUtils { /** * Checks for invalid resource input paths rejecting the following: *