{"id":"CVE-2026-40075","aliases":["CVE-2026-40075","GHSA-jjgj-cx3q-pw4w"],"related":[],"kind":"vulnerability","state":"published","title":"OpenMRS Core arbitrary file read via path traversal in ModuleResourcesServlet","summary":"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.\n\nAn 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.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"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.\n\nAn 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.","source":"cvelist"},{"lang":"en","text":"## Affected Versions\n\nversion ≤ 2.7.8 (latest version at time of disclosure)\n\nhttps://github.com/openmrs/openmrs-core\n\n## Impact\n\nThe `/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).\n\nThis 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.\n\n> **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.\n> \n\n## Steps to Reproduce\n\n1. Identify a valid installed module ID on the target OpenMRS instance (e.g., `legacyui`).\n2. Send the following HTTP request:\n\n<img width=\"1038\" height=\"798\" alt=\"image\" src=\"https://github.com/user-attachments/assets/7d10ee0e-4d81-4c01-bc84-a1bf5715f170\" />\n\n3. The server responds with HTTP 200 and the contents of `/etc/passwd`:\n\n<img width=\"1028\" height=\"843\" alt=\"image\" src=\"https://github.com/user-attachments/assets/b6806a7e-ff52-4f51-8f7f-7ea4e9754d10\" />\n\n\n## Root Cause Analysis\n\nThe vulnerability exists in `ModuleResourcesServlet.java` (`web/src/main/java/org/openmrs/module/web/ModuleResourcesServlet.java`).\n\nThe `getFile()` method constructs a filesystem path from user-controlled input without performing path boundary validation:\n\n```java\nprotected File getFile(HttpServletRequest request) {\n    // Step 1: User-controlled path input\n    String path = request.getPathInfo();\n\n    // Step 2: Extract module from path prefix\n    Module module = ModuleUtil.getModuleForPath(path);\n    if (module == null) { return null; }\n\n    // Step 3: Strip module ID prefix — no traversal check\n    String relativePath = ModuleUtil.getPathForResource(module, path);\n\n    // Step 4: Concatenate into absolute path\n    String realPath = getServletContext().getRealPath(\"\")\n        + MODULE_PATH\n        + module.getModuleIdAsPath()\n        + \"/resources\"\n        + relativePath;  // contains \"/../../../etc/passwd\"\n\n    realPath = realPath.replace(\"/\", File.separator);\n\n    // Step 5: No normalize().startsWith() boundary check\n    File f = new File(realPath);\n    if (!f.exists()) { return null; }\n\n    return f;  // Arbitrary file returned to client\n}\n```\n\nThe helper method `ModuleUtil.getPathForResource()` only strips the module ID prefix and performs no sanitization:\n\n```java\npublic static String getPathForResource(Module module, String path) {\n    if (path.startsWith(\"/\")) {\n        path = path.substring(1);\n    }\n    return path.substring(module.getModuleIdAsPath().length());\n    // Returns unsanitized remainder, e.g., \"/../../../../../../etc/passwd\"\n}\n```\n\nThe resulting path resolves as:\n\n```\n{webapp}/WEB-INF/view/module/legacyui/resources/../../../../../../etc/passwd\n  → /etc/passwd\n```\n\nNotably, the same codebase already implements correct path traversal protection in `StartupFilter.java`:\n\n```java\n// StartupFilter.java — correct protection\nfullFilePath = fullFilePath.resolve(httpRequest.getPathInfo());\nif (!(fullFilePath.normalize().startsWith(filePath))) {\n    log.warn(\"Detected attempted directory traversal...\");\n    return;  // Request rejected\n}\n```\n\nThis check is absent from `ModuleResourcesServlet`.\n\n## Remediation\n\nAdd 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:\n\n```java\nFile f = new File(realPath);\nPath allowedBase = Paths.get(getServletContext().getRealPath(\"\"), \"WEB-INF\", \"view\", \"module\");\nif (!f.toPath().normalize().startsWith(allowedBase.normalize())) {\n    log.warn(\"Blocked path traversal attempt: {}\", request.getPathInfo());\n    return null;\n}\n```\n\nThis is consistent with the existing pattern used in `StartupFilter.java` and `TestInstallUtil.java` within the same project.","format":"markdown","source":"ghsa"},{"lang":"es","text":"OpenMRS Core es una plataforma de sistema de registro médico electrónico de código abierto. En las versiones 2.7.8 y anteriores, y en las versiones 2.8.0 a 2.8.5, el endpoint '/openmrs/moduleResources/{moduleid}' es vulnerable a un ataque de salto de ruta. El ModuleResourcesServlet construye una ruta del sistema de archivos a partir de una entrada controlada por el usuario sin realizar una validación de límites de ruta - el método getFile() concatena la ruta proporcionada por el usuario en una ruta absoluta del sistema de archivos sin llamar a normalize() ni verificar que el resultado permanezca dentro del directorio de recursos del módulo permitido. Debido a que este endpoint sirve recursos estáticos necesarios para renderizar la página de inicio de sesión, no está protegido por filtros de autenticación, lo que permite la explotación no autenticada.\n\nUn atacante puede atravesar directorios y leer archivos arbitrarios del sistema de archivos del servidor, incluyendo /etc/p4ssd y archivos de configuración de aplicaciones que contienen credenciales de base de datos. La explotación exitosa requiere que la implementación objetivo se ejecute en versiones de Apache Tomcat anteriores a la 8.5.31, donde el bypass del parámetro de ruta '..;' no es mitigado por el contenedor. Las implementaciones en Tomcat 8.5.31 o posterior y Tomcat 9.0.10 o posterior están protegidas a nivel de contenedor, aunque el defecto de código subyacente permanece. Este problema ha sido solucionado en versiones posteriores a la 2.7.8 (dentro de la rama 2.7.x) y en la versión 2.8.6 y posteriores.","source":"nvd"}],"published":"2026-05-04T17:18:48.000Z","modified":"2026-07-24T21:10:00.143Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N","score":8.2,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N","score":8.2,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N","score":7.5,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N","rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N","score":7.5,"rating":"HIGH"}],"cwes":["CWE-22"],"affected":[{"ranges":[{"version":"<= 2.7.8","status":"affected"},{"version":">= 2.8.0, <= 2.8.5","status":"affected"}],"vendor":"openmrs","product":"openmrs-core","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","lastAffected":"2.7.8"}],"ecosystem":"Maven","package":"org.openmrs.web:openmrs-web","purl":"pkg:maven/org.openmrs.web/openmrs-web","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"2.8.0","status":"affected","fixed":"2.8.6"}],"ecosystem":"Maven","package":"org.openmrs.web:openmrs-web","purl":"pkg:maven/org.openmrs.web/openmrs-web","source":"ghsa"},{"ranges":[{"status":"affected","lastAffected":"2.7.8"},{"status":"affected","introduced":"2.8.0","lastAffected":"2.8.5"}],"vendor":"openmrs","product":"openmrs","cpe":"cpe:2.3:a:openmrs:openmrs:*:*:*:*:*:*:*:*","source":"nvd"}],"references":[{"url":"https://github.com/openmrs/openmrs-core/security/advisories/GHSA-jjgj-cx3q-pw4w","tags":["exploit","mitigation","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-40075","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/openmrs/openmrs-core","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"yes","technicalImpact":"partial","date":"2026-05-06T14:32:34.742Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-40075","url":"https://www.cve.org/CVERecord?id=CVE-2026-40075","licence":"CVE Terms of Use","modified":"2026-05-06T14:33:02.685Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-jjgj-cx3q-pw4w","url":"https://github.com/advisories/GHSA-jjgj-cx3q-pw4w","licence":"CC-BY-4.0","modified":"2026-05-08T15:51:33.312Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-40075","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-40075","licence":"Public domain","modified":"2026-07-24T21:10:00.143Z"}],"updatedAt":"2026-11-25T22:59:20.649Z","epss":{"score":0.00558,"percentile":0.47875,"date":"2026-12-01T12:00:22.000Z"}}