漏洞概述
VMware Spring Framework是美国威睿(VMware)公司的一套开源的Java、JavaEE应用程序框架。该框架可帮助开发人员构建高质量的应用。
近期,监测到Spring Framework在特定条件下,存在目录遍历漏洞(网宿评分:高危、CVSS 3.1 评分:7.5):
当同时满足使用 RouterFunctions 和 FileSystemResource 来处理和提供静态文件时,攻击者可构造恶意请求遍历读取系统上的文件。
目前该漏洞POC状态已在互联网公开,建议客户尽快做好自查及防护。
受影响版本
Spring Framework 5.3.0 - 5.3.39
Spring Framework 6.0.0 - 6.0.23
Spring Framework 6.1.0 - 6.1.12
其他更旧或者官方已不支持的版本
漏洞分析
根据漏洞描述(https://spring.io/security/cve-2024-38816)可知,关键变更在于如何处理静态资源路径。
这里改了两处,分别是:
webflux --> org.springframework.web.reactive.function.server.PathResourceLookupFunction
webmvc --> org.springframework.web.servlet.function.PathResourceLookupFunction
它们都旨在为 Web 应用程序提供静态内容的访问。
以webmvc --> org.springframework.web.servlet.function.PathResourceLookupFunction为例,展开分析。
先是动态处理了资源请求,确保只返回有效并且可访问的资源。
@Override
public Optional<Resource> apply(ServerRequest request) {
PathContainer pathContainer = request.requestPath().pathWithinApplication();
if (!this.pattern.matches(pathContainer)) {
return Optional.empty();
}
pathContainer = this.pattern.extractPathWithinPattern(pathContainer);
String path = processPath(pathContainer.value());
if (path.contains("%")) {