
In-depth analysis of CVE-2024-38819, a Spring WebFlux file traversal vulnerability, with code-level breakdown, PoC, and mitigation strategies including filters and IPS rules.
File-Traversal (Path Traversal) vulnerability allows an attacker to bypass file system permissions in a web application and access arbitrary files, and is a type of attack designated as CWE-22.
Spring WebFlux is a module introduced in Spring 5 that supports reactive programming, enabling asynchronous non-blocking application development. WebFlux.fn provides functional endpoint routing, supporting concise and flexible routing configuration using lambda expressions.
CVE-2024-38819 occurs in applications using WebFlux.fn and WebMVC.fn. This document aims to examine how the vulnerability occurs in WebFlux by reviewing the code flow and to explore corresponding countermeasures.
[Figure 1] FileApplication.java
[Figure 2] PathResourceLookupFunction.class - apply
[Figure 3] PathResourceLookupFunction.class - isInvalidPath
[Figure 4] StringUtils.class - cleanPath
[Figure 5] PathResourceLookupFunction.class - apply - 2
[Figure 6] PathResourceLookupFunction.class - isResourceUnderLocation
[Figure 7] StringUtils.class - cleanPath -2
Currently, the test was conducted on Windows with C:/file, but this case is very dangerous when combined with symbolic links on Linux.
(When setting ../../ twice, it behaves normally; vulnerability occurs only with a single ../ )

Attack combined with symbolic link on Linux server
public RouterFunction<ServerResponse> staticResourceRouter() {
return RouterFunctions.resources("/static/**", new FileSystemResource("/app/static/"));
}
Add symbolic link: ln -s /static /app/static/link, then attack

We have reviewed the flow of File Traversal (CVE-2024-38819) in the Spring Webflux environment. Since this attack method steals server information, countermeasures are important. We propose updating to the latest version, creating additional validation logic, and blocking via IPS.
@Bean
public RouterFunction<ServerResponse> staticResourceRouter() {
return RouterFunctions.resources("/static/**", new FileSystemResource("C:/file"))
.filter((request, next) -> {
String path = request.path();
if (path.contains("..")) {
if(!StringUtils.cleanPath(path).contains("../")) {
return ServerResponse.status(HttpStatus.FORBIDDEN).bodyValue("Vuln path access.");
}
}
return next.handle(request);
});
}
Block all URL requests that cause parent directory movement (../)
We have examined File Traversal through Webflux. This vulnerability occurred when the problem originating from the StringUtils.cleanPath() logic was not recognized and used.
(POC)
https://github.com/masa42/CVE-2024-38819-POC
(Spring Official)
https://spring.io/security/cve-2024-38819
(CVE-DETAIL)
https://www.cvedetails.com/cve/CVE-2024-38819/
(NIST)
https://nvd.nist.gov/vuln/detail/cve-2024-38819