Summary
OpenMRS Core's REST module upload endpoint is vulnerable to a Zip Slip path traversal issue during automatic extraction of uploaded .omod archives.
An authenticated user with module upload permissions can craft archive entries that escape the intended module directory, write arbitrary files into the web application, and potentially achieve remote code execution by deploying malicious JSPs.
Affected context
This vulnerability affects OpenMRS Core deployments that:
- Enable the REST API endpoint
POST /openmrs/ws/rest/v1/modulefor module uploads - Automatically extract
.omodarchives viaWebModuleUtil.startModule() - Rely on the
module.allow_web_adminruntime property to restrict module administration
The issue is present when ZIP entry paths under web/module/ are trusted without proper normalization and boundary checks, allowing crafted paths to escape the module directory and land in sensitive locations such as the webapp root.
Exploit preconditions
- Attack surface: OpenMRS REST API at
POST /openmrs/ws/rest/v1/module - Required access: Authenticated account with permission to upload modules through the REST API (even where
module.allow_web_adminis set to disallow web admin in the legacy UI) - Trigger point: Server-side extraction of
.omodarchives inWebModuleUtil.startModule()after an upload - Why exploitation is possible:
- ZIP entries are only checked to see if the full entry name starts with
.. - Paths like
web/module/../../../../malicious.jspare accepted because they do not start with.. - The remaining path is concatenated to the target directory without normalization or enforcing that the final path stays inside the intended module directory
- Application containers typically map such locations directly under the web application root, making uploaded JSPs executable via HTTP requests
Why this happens
The underlying issue is a classic Zip Slip style path traversal (CWE-22) during archive extraction.
The extraction code validates ZIP entries with an overly simplistic check that only rejects paths whose full entry string begins with .., but it does not:
- Normalize the path to resolve
../sequences, or - Re-validate that the resolved filesystem path is still under the intended module directory
As a result, an attacker can include entries like web/module/../../../../malicious.jsp, which are treated as valid relative paths. When concatenated to the module directory, these paths escape the expected extraction boundary and allow writing arbitrary files elsewhere in the application's filesystem, including executable code locations such as the webapp root.
Potential impact
- Arbitrary file write on the server filesystem within the web application context
- Deployment and execution of malicious JSPs or other server-side resources
- Authenticated remote code execution under the application's runtime privileges
- Tampering with existing application files, configuration, or views
- Facilitation of further lateral movement or persistence within the hosting environment
General mitigation guidance
Effective mitigation focuses on hardening archive extraction and enforcing strict file system boundaries:
- Constrain extraction paths:
- Normalize each ZIP entry path (e.g., resolve
.and..components) before use. - Reject any entry whose normalized target path would end up outside the intended module base directory.
- Implement robust path validation:
- Use filesystem-aware APIs to build the target path and verify that the final canonical path starts with the expected module directory.
- Reject absolute paths and any entries containing traversal sequences (
../) after normalization. - Limit upload capabilities:
- Restrict module upload permissions to tightly controlled administrative roles and service accounts.
- Align REST API authorization with the same policy enforced in the legacy UI so that
module.allow_web_adminor equivalent configuration is consistently respected. - Reduce code execution surfaces:
- Avoid or minimize executable content (e.g., JSP) deployment via module uploads.
- Run the application under a least-privilege account and restrict write access to executable directories.
- Defense-in-depth:
- Consider mounting webroot or sensitive directories as read-only where operationally feasible.
- Log and monitor module uploads and extraction activity for anomalous patterns.
How teams detect issues like this
Organizations can detect this class of vulnerability and its abuse through several complementary approaches:
- Static code analysis:
- Scan for custom ZIP extraction logic using
java.util.zipor similar APIs where: - ZIP entry names are concatenated directly into filesystem paths, and
- There is no path normalization or canonical path boundary check.
- Define rules or patterns that flag any use of
../handling that relies solely on string prefix checks. - Manual code review:
- Examine module and plugin upload handlers, focusing on file extraction and write operations.
- Verify that all archive extraction code validates that the resolved target path stays within an allowed base directory.
- Confirm that authorization and runtime properties (such as
module.allow_web_admin) are consistently enforced across UI and API endpoints. - Runtime monitoring and logging:
- Enable detailed server logs for file writes during module installation and updates.
- Monitor for uploaded files appearing under unexpected paths, particularly within webapp roots or other executable directories.
- Track unusual access patterns to newly created JSPs or other dynamic resources.
- Security testing:
- Incorporate Zip Slip test cases into regular penetration tests and CI/CD security checks.
- Use automated security scanners that explicitly test archive upload endpoints for path traversal on extraction.

