Summary
OpenMRS Core contains a path traversal vulnerability in the /openmrs/moduleResources/{moduleid} endpoint, where user-controlled paths are concatenated directly into filesystem paths without boundary validation.
On vulnerable servlet containers, an unauthenticated attacker can traverse directories and read arbitrary files from the server, including sensitive system and configuration files, by crafting specially formatted resource paths.
Affected context
This vulnerability affects OpenMRS Core deployments (2.7.8 and earlier, and 2.8.0–2.8.5) that expose the /openmrs/moduleResources/{moduleid} endpoint for serving static module resources.
The issue occurs when the ModuleResourcesServlet derives filesystem paths directly from HTTP request parameters and relies on the servlet container for path normalization.
It is most impactful on instances running on Apache Tomcat versions prior to 8.5.31 or 9.0.10, where the ..; path parameter bypass is not mitigated by the container, allowing directory traversal outside the intended module resource directory.
Exploit preconditions
- Attack surface: HTTP(S) access to the
/openmrs/moduleResources/{moduleid}endpoint. - Required access: No authentication required; the endpoint is used to load resources for the login page and is accessible to anonymous users.
- Environmental dependency: OpenMRS deployed on Apache Tomcat versions earlier than 8.5.31 (or 9.0.10), where container-level normalization does not block traversal sequences such as
..;. - Trigger point: A crafted request parameter or path segment that includes directory traversal sequences, which the servlet uses to construct an absolute filesystem path.
- Why exploitation is possible: The
getFile()method concatenates user-supplied path components into an absolute path without usingnormalize()or verifying that the resulting path remains within the authorized module resources directory.
Why this happens
The root cause is a classic directory traversal pattern where the application constructs filesystem paths directly from untrusted input without enforcing path boundaries.
In this case, the ModuleResourcesServlet builds an absolute path by appending a user-specified resource path to a base module resources directory and does not normalize the resulting path or confirm that it still resides within the intended directory tree.
This aligns with CWE-22: Improper Limitation of a Pathname to a Restricted Directory, because attackers can inject traversal sequences (e.g., ../) or container-specific bypass forms to escape the allowed directory and access arbitrary files on the server.
Potential impact
- Reading arbitrary files accessible to the Tomcat/OpenMRS process on the server filesystem.
- Disclosure of sensitive system files such as
/etc/passwdor OS-specific equivalents. - Exposure of OpenMRS and application configuration files, including database connection strings and credentials.
- Facilitating further compromise through credential reuse or targeted attacks on backend databases.
- Gaining insight into application internals, environment layout, and security controls that can aid in subsequent exploitation.
General mitigation guidance
Effective mitigation centers on enforcing strict path boundaries and reducing trust in user-supplied resource paths:
- Resolve and normalize all filesystem paths derived from HTTP input before use and confirm that the canonical path remains under the expected base directory.
- Use vetted utility functions or frameworks for safe path handling rather than manual string concatenation.
- Implement allowlists of resource names or subpaths when feasible, especially for static resources, instead of serving arbitrary user-specified filenames.
- Avoid relying solely on container-level protections; enforce application-layer checks on every path that interacts with the filesystem.
- Run the OpenMRS/Tomcat process with least-privilege filesystem permissions, limiting which directories and files can be read even if traversal is attempted.
How teams detect issues like this
Detection can combine code-centric reviews and runtime monitoring:
- Static analysis: Configure SAST rules to flag any use of user-controlled data in filesystem APIs (e.g.,
File,Paths.get,FileInputStream) without prior normalization and base-directory checks. - Code review: Look for custom servlets or controllers that construct paths via string concatenation, especially in resource-serving endpoints, and verify that they validate and canonicalize paths.
- Security testing: Incorporate automated and manual directory traversal checks into application security testing, including variant encodings (
..;, URL-encoded characters, mixed separators) specific to the target container. - Runtime monitoring: Use web application firewalls or reverse proxies with rules that detect and log suspicious path traversal patterns in URLs, query parameters, and headers for further investigation.

