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 277609e011f..e1cb65c9327 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,6 +19,7 @@ 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; @@ -182,6 +183,14 @@ public abstract class ResourceHandlerUtils { * @return {@code true} if the path is invalid, {@code false} otherwise */ public static boolean isInvalidPath(String path) { + String pathLowerCase = path.toLowerCase(Locale.ROOT); + if (pathLowerCase.contains("web-inf") || pathLowerCase.contains("meta-inf")) { + if (logger.isWarnEnabled()) { + logger.warn(LogFormatUtils.formatValue( + "Path with \"WEB-INF\" or \"META-INF\": [" + path + "]", -1, true)); + } + return true; + } if (path.contains(":/")) { String relativePath = (path.charAt(0) == '/' ? path.substring(1) : path); if (ResourceUtils.isUrl(relativePath) || relativePath.startsWith("url:")) { 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 367654fa7d5..2a5d348c91b 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 @@ -19,6 +19,7 @@ package org.springframework.web.servlet.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; @@ -183,6 +184,14 @@ public abstract class ResourceHandlerUtils { * @return {@code true} if the path is invalid, {@code false} otherwise */ public static boolean isInvalidPath(String path) { + String pathLowerCase = path.toLowerCase(Locale.ROOT); + if (pathLowerCase.contains("web-inf") || pathLowerCase.contains("meta-inf")) { + if (logger.isWarnEnabled()) { + logger.warn(LogFormatUtils.formatValue( + "Path with \"WEB-INF\" or \"META-INF\": [" + path + "]", -1, true)); + } + return true; + } if (path.contains(":/")) { String relativePath = (path.charAt(0) == '/' ? path.substring(1) : path); if (ResourceUtils.isUrl(relativePath) || relativePath.startsWith("url:")) {