CVE-2026-40075: OpenMRS Core arbitrary file read via path traversal in ModuleResourcesServlet
Affected Versions
version ≤ 2.7.8 (latest version at time of disclosure)
https://github.com/openmrs/openmrs-core
Impact
The /openmrs/moduleResources/{moduleid} endpoint in OpenMRS Core is vulnerable to a path traversal attack. The ModuleResourcesServlet does not properly validate user-supplied path input, allowing an attacker to traverse directories and read arbitrary files from the server filesystem (e.g., /etc/passwd, application configuration files containing database credentials).
This endpoint serves static module resources (CSS, JS, images) and is not protected by authentication filters, as these resources are required for rendering the login page. Therefore, this vulnerability can be exploited by an unauthenticated attacker.
Note: Successful exploitation requires the target deployment to run on Apache Tomcat < 8.5.31, where the ..; path parameter bypass is not mitigated by the container. Deployments on Tomcat ≥ 8.5.31 / ≥ 9.0.10 are protected at the container level, though the underlying code defect remains.
Steps to Reproduce
1. Identify a valid installed module ID on the target OpenMRS instance (e.g., legacyui). 2. Send the following HTTP request:
<img width="1038" height="798" alt="image" src="https://github.com/user-attachments/assets/7d10ee0e-4d81-4c01-bc84-a1bf5715f170" />
3. The server responds with HTTP 200 and the contents of /etc/passwd:
<img width="1028" height="843" alt="image" src="https://github.com/user-attachments/assets/b6806a7e-ff52-4f51-8f7f-7ea4e9754d10" />
Root Cause Analysis
The vulnerability exists in ModuleResourcesServlet.java (web/src/main/java/org/openmrs/module/web/ModuleResourcesServlet.java).
The getFile() method constructs a filesystem path from user-controlled input without performing path boundary validation:
java protected File getFile(HttpServletRequest request) { // Step 1: User-controlled path input String path = request.getPathInfo();
// Step 2: Extract module from path prefix Module module = ModuleUtil.getModuleForPath(path); if (module == null) { return null; }
// Step 3: Strip module ID prefix — no traversal check String relativePath = ModuleUtil.getPathForResource(module, path);
// Step 4: Concatenate into absolute path String realPath = getServletContext().getRealPath("") + MODULEPATH + module.getModuleIdAsPath() + "/resources" + relativePath; // contains "/../../../etc/passwd"
realPath = realPath.replace("/", File.separator);
// Step 5: No normalize().startsWith() boundary check File f = new File(realPath); if (!f.exists()) { return null; }
return f; // Arbitrary file returned to client }
The helper method ModuleUtil.getPathForResource() only strips the module ID prefix and performs no sanitization:
java public static String getPathForResource(Module module, String path) { if (path.startsWith("/")) { path = path.substring(1); } return path.substring(module.getModuleIdAsPath().length()); // Returns unsanitized remainder, e.g., "/../../../../../../etc/passwd" }
The resulting path resolves as:
{webapp}/WEB-INF/view/module/legacyui/resources/../../../../../../etc/passwd → /etc/passwd
Notably, the same codebase already implements correct path traversal protection in StartupFilter.java:
java // StartupFilter.java — correct protection fullFilePath = fullFilePath.resolve(httpRequest.getPathInfo()); if (!(fullFilePath.normalize().startsWith(filePath))) { log.warn("Detected attempted directory traversal..."); return; // Request rejected }
This check is absent from ModuleResourcesServlet.
Remediation
Add a path boundary check after constructing realPath and before returning the File object. The fix should use normalize() + startsWith() to ensure the resolved path stays within the allowed module resources directory:
java File f = new File(realPath); Path allowedBase = Paths.get(getServletContext().getRealPath(""), "WEB-INF", "view", "module"); if (!f.toPath().normalize().startsWith(allowedBase.normalize())) { log.warn("Blocked path traversal attempt: {}", request.getPathInfo()); return null; }
This is consistent with the existing pattern used in StartupFilter.java and TestInstallUtil.java within the same project.
Other sources
OpenMRS Core is an open source electronic medical record system platform. In versions 2.7.8 and earlier and versions 2.8.0 through 2.8.5, the /openmrs/moduleResources/{moduleid} endpoint is vulnerable to a path traversal attack. The ModuleResourcesServlet constructs a filesystem path from user-controlled input without performing path boundary validation — the getFile() method concatenates the user-supplied path into an absolute filesystem path without calling normalize() or checking that the result stays within the allowed module resources directory. Because this endpoint serves static resources required for rendering the login page, it is not protected by authentication filters, allowing unauthenticated exploitation.
An attacker can traverse directories and read arbitrary files from the server filesystem, including /etc/passwd and application configuration files containing database credentials. Successful exploitation requires the target deployment to run on Apache Tomcat versions prior to 8.5.31, where the ..; path parameter bypass is not mitigated by the container. Deployments on Tomcat 8.5.31 or later and Tomcat 9.0.10 or later are protected at the container level, though the underlying code defect remains. This issue has been fixed in versions after 2.7.8 (within the 2.7.x branch) and in version 2.8.6 and later.
— MITRE
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
maven/org.openmrs.web:openmrs-webto a version that resolves this vulnerability.Fixed in 2.8.6 - Upgrade
Upgrade
openmrs-coreto a version that resolves this vulnerability.Fixed in 2.8.6 - Configuration
Add a path boundary check after constructing realPath and before creating/returning the File object (e.g., validate that f.toPath().normalize().startsWith(allowedBase.normalize()) and reject/block when it does not).
OpenMRS Core ModuleResourcesServlet (web/src/main/java/org/openmrs/module/web/ModuleResourcesServlet.java) Path boundary validation for constructed realPath = Use normalize() + startsWith() boundary check after constructing realPath and before returning the File object - Configuration
If the constructed path does not normalize().startsWith(allowedBase.normalize()), reject the request (e.g., return null / do not serve the file) and optionally log a warning like "Blocked path traversal attempt" using the request.getPathInfo().
OpenMRS Core ModuleResourcesServlet (web/src/main/java/org/openmrs/module/web/ModuleResourcesServlet.java) Traversal mitigation = Reject paths that fail the boundary check - Compensating control
Ensure deployments are on Apache Tomcat versions protected at the container level: Tomcat 8.5.31 or later, or Tomcat 9.0.10 or later (note: the underlying code defect remains, but exploitation via the ..; path parameter bypass is mitigated by the container).
Event History
Frequently Asked Questions
What is the severity of CVE-2026-40075?
CVE-2026-40075 is classified as a high-severity vulnerability due to its potential to allow path traversal attacks.
How do I fix CVE-2026-40075?
To remediate CVE-2026-40075, upgrade to version 2.8.6 or later of OpenMRS Core.
What systems are affected by CVE-2026-40075?
CVE-2026-40075 affects versions of OpenMRS Core up to and including 2.7.8.
What type of vulnerability is CVE-2026-40075?
CVE-2026-40075 is a path traversal vulnerability in the ModuleResourcesServlet of OpenMRS Core.
Can CVE-2026-40075 lead to data exposure?
Yes, CVE-2026-40075 can lead to unauthorized access to files on the server, potentially exposing sensitive data.