/

CVE-2026-40076

Severity:

HIGH RISK

(8.8)

Path Traversal / Zip Slip in OpenMRS Module Upload Endpoint

CVE-2026-40076

Analyzed

Vulnerability type

Category:

Path Traversal / Zip Slip

CWE:

CWE-22

Impact:

Authenticated Remote Code Execution via Arbitrary File Write

Severity:

HIGH RISK

(8.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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/module for module uploads
  • Automatically extract .omod archives via WebModuleUtil.startModule()
  • Rely on the module.allow_web_admin runtime 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_admin is set to disallow web admin in the legacy UI)
  • Trigger point: Server-side extraction of .omod archives in WebModuleUtil.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.jsp are 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_admin or 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.zip or 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.

Sources

SourceLink
github.comgithub.com/openmrs/openmrs-core/security/advisories/GHSA-78fc-9688-w8xw

Frequently asked

questions

Yes, it is exploitable remotely via the REST API, but only by authenticated users with module upload rights. Attackers must be able to send crafted .omod uploads to the /openmrs/ws/rest/v1/module endpoint.

The attacker needs at least the level of access required to upload modules through the REST API. However, environments that relied solely on the module.allow_web_admin property to block web-based administration might inadvertently grant this capability through the REST path.

Normalize and validate extracted file paths before writing to disk, and enforce that the canonical target path always remains inside an expected base directory. Reject any absolute paths, any normalized paths that escape the base directory, and ensure consistent strict authorization checks are applied to all module upload interfaces.

Adopt a standard, well-reviewed utility or library for archive extraction that includes Zip Slip protections by default, and mandate canonical-path boundary checks in coding guidelines. Coupled with principle-of-least-privilege for file system access, thorough code review of upload and extraction paths, and automated static analysis targeting path traversal patterns, this significantly reduces the risk of comparable vulnerabilities.

Find out what's already
exploitable in your codebase.