{"id":"CVE-2026-40076","kind":"vulnerability","aliases":["CVE-2026-40076","GHSA-78fc-9688-w8xw"],"related":[],"title":"OpenMRS Module Upload Vulnerable to Path Traversal (Zip Slip)","description":"## 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 endpoint `POST /openmrs/ws/rest/v1/module` is vulnerable to a path traversal (Zip Slip) attack. An authenticated attacker can upload a crafted `.omod` archive containing ZIP entries with directory traversal sequences. Upon automatic extraction by the server, the incomplete path validation in `WebModuleUtil.startModule()` fails to prevent entries such as `web/module/../../../../malicious.jsp` from being written outside the intended module directory. If the traversal target falls within the web application root (e.g., `/usr/local/tomcat/webapps/openmrs/`), the attacker achieves arbitrary file write and subsequent Remote Code Execution.\n\nNotably, other extraction methods in the same codebase (`ModuleUtil.expandJar()`, `TestInstallUtil.addZippedTestModules()`) are properly protected with `normalize().startsWith()` checks — this vulnerability is an oversight where the same fix was not applied.\n\nFurthermore, the `module.allow_web_admin` runtime property, which is intended to restrict administrators from managing modules via the web interface, only gates the Legacy UI controller entry point. The REST API endpoint `POST /openmrs/ws/rest/v1/module` does not check this property, allowing this restriction to be fully bypassed.\n\n## Steps to Reproduce\n\n1. Construct a malicious `.omod` file (which is a ZIP/JAR archive) containing a ZIP entry with a path traversal payload in its entry name, such as `web/module/../../../../<target_filename>`. Upload this file to `POST /openmrs/ws/rest/v1/module` with valid admin credentials via Basic Auth.\n\n<img width=\"1986\" height=\"1102\" alt=\"image\" src=\"https://github.com/user-attachments/assets/647f15de-7e8c-40b9-aba9-d4db5d2e0b52\" />\n\n<img width=\"2048\" height=\"1078\" alt=\"image\" src=\"https://github.com/user-attachments/assets/301412a0-e3b0-4afb-91c2-e9739de3080d\" />\n\n\n2. The server parses and loads the module. During `WebModuleUtil.startModule()`, entries under `web/module/` are automatically extracted. The existing check `Paths.get(name).startsWith(\"..\")` only blocks entries beginning with `..`, so an entry starting with `web/module/` passes the check. The `../` sequences in the remaining path cause the file to be written outside the intended `WEB-INF/view/module/` directory — for example, into the web application root at `/usr/local/tomcat/webapps/openmrs/`.\n\n<img width=\"1439\" height=\"141\" alt=\"image\" src=\"https://github.com/user-attachments/assets/4bda3b1e-a80e-42ed-af2b-a1da53e8db03\" />\n\n3. The traversed file is now accessible under the web application root. If the written file is a JSP script, accessing it via the browser triggers server-side execution, achieving RCE.\n\n<img width=\"1482\" height=\"300\" alt=\"image\" src=\"https://github.com/user-attachments/assets/61936002-78cd-4203-80f0-f0a8702b216c\" />\n\n## Root Cause Analysis\n\nThe vulnerability exists in `WebModuleUtil.startModule()` (`web/src/main/java/org/openmrs/module/web/WebModuleUtil.java`).\n\n### Vulnerable code:\n\n```java\nEnumeration<JarEntry> entries = jarFile.entries();\nwhile (entries.hasMoreElements()) {\n    JarEntry entry = entries.nextElement();\n    String name = entry.getName();\n\n    // ❌ Incomplete check — only blocks entries starting with \"..\"\n    if (Paths.get(name).startsWith(\"..\")) {\n        throw new UnsupportedOperationException(\"...\");\n    }\n\n    if (name.startsWith(\"web/module/\")) {\n        String filepath = name.substring(11);\n        StringBuilder absPath = new StringBuilder(realPath + \"/WEB-INF\");\n        absPath.append(\"/view/module/\");\n        absPath.append(mod.getModuleIdAsPath()).append(\"/\").append(filepath);\n\n        // ❌ No normalize() or startsWith() boundary check before writing\n        File outFile = new File(absPath.toString().replace(\"/\", File.separator));\n        outStream = new FileOutputStream(outFile, false);\n        inStream = jarFile.getInputStream(entry);\n        OpenmrsUtil.copyFile(inStream, outStream);\n    }\n}\n```\n\n**Why the check fails:** For an entry named `web/module/foo/../../../../evil.jsp`, `Paths.get(name)` starts with `web`, not `..`, so the check passes. After `name.substring(11)`, the filepath `foo/../../../../evil.jsp` is concatenated directly into the output path without normalization, resulting in a write outside the intended directory.\n\n### Correctly protected code in the same codebase:\n\n**`ModuleUtil.expandJar()`:**\n\n```java\n// ✅ Correct — uses normalize().startsWith()\nif (!parent.toPath().normalize().startsWith(docBase)) {\n    throw new UnsupportedOperationException(\"...\");\n}\n```\n\n**`TestInstallUtil.addZippedTestModules()`:**\n\n```java\n// ✅ Correct — uses normalize().startsWith()\nif (!zipEntryFile.toPath().normalize().startsWith(moduleRepository.toPath().normalize())) {\n    throw new IOException(\"Bad zip entry\");\n}\n```\n\nThe fix pattern is already known and applied elsewhere in the codebase. `WebModuleUtil.startModule()` is an oversight.\n\n### Bypass of `module.allow_web_admin`\n\nThe `module.allow_web_admin` property only restricts module operations at the Legacy UI layer (`ModuleListController`). The REST API endpoint does not consult this property:\n\n```\nLegacy UI:  POST /admin/modules/moduleList.form → allowAdmin() check → [BLOCKED]\nREST API:   POST /ws/rest/v1/module             → No allowAdmin() check → [ALLOWED]\n                ↓\n        ModuleFactory.loadModule()\n                ↓\n        WebModuleUtil.startModule()   ← Zip Slip here, no allowAdmin check\n                ↓\n        FileOutputStream.write()      ← Arbitrary file write\n```\n\n## Remediation\n\nAdd `normalize().startsWith()` boundary validation before writing, consistent with the existing pattern in `ModuleUtil.expandJar()`:\n\n```java\nFile outFile = new File(absPath.toString().replace(\"/\", File.separator));\n\n// ✅ Add this check\nif (!outFile.toPath().normalize().startsWith(\n        Paths.get(realPath, \"WEB-INF\").normalize())) {\n    throw new UnsupportedOperationException(\n        \"Zip entry '\" + name + \"' would be written outside the allowed directory.\");\n}\n```\n\nAdditionally, enforce the `module.allow_web_admin` restriction consistently across all module upload entry points, including the REST API.","summary":"The OpenMRS REST endpoint for uploading modules extracts ZIP entries without checking that paths stay inside the module directory. An authenticated attacker can write a JSP file into the web application root and run code on the server.","severity":"critical","cvss":9.4,"epss":0.00853,"exploited":false,"exploited_at":null,"products":[{"name":"org.openmrs.web:openmrs-web","fixed":[],"affected":"<= 2.7.8","ecosystem":"maven"},{"name":"org.openmrs.web:openmrs-web","fixed":[],"affected":">= 2.8.0, <= 2.8.5","ecosystem":"maven"},{"name":"openmrs","fixed":[],"affected":"<= 2.7.8","ecosystem":"vendor"},{"name":"openmrs","fixed":[],"affected":">= 2.8.0, <= 2.8.5","ecosystem":"vendor"}],"ecosystems":["maven","vendor"],"tags":["cwe-22","java","openmrs","package","tomcat"],"not_affected_if":["versions-outside-range"],"how_to_check":"- Check the `openmrs-web` version in the deployed WAR or WEB-INF/lib; it is affected at `<= 2.7.8` and `2.8.0` through `2.8.5`.\n- Confirm whether the REST endpoint `POST /openmrs/ws/rest/v1/module` is reachable from outside your network.","fix":null,"status":"open","published_at":"2026-05-04T17:39:31+00:00","first_seen_at":"2026-11-12T18:20:03+00:00","triaged_at":"2026-11-12T18:21:52+00:00","updated_at":"2026-11-12T18:40:39+00:00","category":"package","confidence":0.8,"triage":{"at":"2026-11-12T18:21:52Z","model":"claude-haiku-5-5","output":{"fix":"unknown","reach":"internet","title":"OpenMRS: module upload path traversal lets an admin write files outside module folder","impact":"high","summary":"The OpenMRS REST endpoint for uploading modules extracts ZIP entries without checking that paths stay inside the module directory. An authenticated attacker can write a JSP file into the web application root and run code on the server.","audience":"businesses","category":"package","nicknames":[],"who_cares":["openmrs","tomcat","java"],"confidence":0.8,"fix_status":"unknown","needs_auth":"yes","worst_case":"attacker writes a JSP file and runs code on server","analyst_note":"Find the fixed versions for openmrs-web in the GHSA-78fc-9688-w8xw advisory or openmrs-core release notes, since the product ranges show no fixed version.","how_to_check":"- Check the `openmrs-web` version in the deployed WAR or WEB-INF/lib; it is affected at `<= 2.7.8` and `2.8.0` through `2.8.5`.\n- Confirm whether the REST endpoint `POST /openmrs/ws/rest/v1/module` is reachable from outside your network.","plain_action":"","product_name":"","needs_analyst":true,"not_affected_if":["versions-outside-range"],"who_is_affected":"Any OpenMRS deployment running `openmrs-web` in the affected ranges where an administrator can upload modules through the REST API. The flaw is in the module upload path, so deployments that do not expose module upload to admins are less exposed. Versions outside the affected ranges are not affected.","user_interaction":"no","product_ecosystem":"","needs_special_setup":"no","severity_if_unknown":"high"},"cost_usd":0.001648,"input_tokens":7012,"output_tokens":1894,"severity_before":"critical"},"analyst_status":"queued","analyst_note":"Find the fixed versions for openmrs-web in the GHSA-78fc-9688-w8xw advisory or openmrs-core release notes, since the product ranges show no fixed version.","search":"'-2026':11A,19A '-22':32B '-40076':12A,20A '/openmrs/openmrs-core':87C '/openmrs/ws/rest/v1/module':92C,230C,278C '/usr/local/tomcat/webapps/openmrs':156C,350C '/view/module':340C,434C '/web-inf':432C '1':246C '11':426C '2':286C '2.7.8':78C '3':351C '78fc':15A '9688':16A 'abspath':428C 'abspath.append':433C,435C 'abspath.tostring':452C 'access':357C,371C 'achiev':159C,381C 'admin':201C,281C 'administr':209C 'affect':75C 'allow':236C 'analysi':385C 'api':227C 'append':437C,438C 'appli':196C 'applic':67B,153C,347C,361C 'arbitrari':160C 'archiv':110C,256C 'attack':58B,101C,104C,158C 'auth':285C 'authent':57B,103C 'automat':119C,300C 'basic':284C 'begin':311C 'block':309C,409C 'boundari':444C 'browser':375C 'bypass':242C 'caus':328C,384C 'check':48B,184C,233C,304C,321C,407C,445C 'code':71B,166C,393C 'codebas':175C 'construct':247C 'contain':111C,257C 'control':222C 'craft':108C 'credenti':282C 'cve':10A,18A 'cwe':31B 'directori':55B,115C,144C,341C 'disclosur':84C 'e.g':155C 'endpoint':40B,90C,228C 'entri':46B,113C,133C,223C,260C,268C,296C,310C,315C,396C,401C,410C,462C 'entries.hasmoreelements':399C 'entries.nextelement':402C 'entry.getname':405C 'enumer':395C 'exampl':343C 'execut':167C,380C 'exist':303C,388C 'extract':44B,120C,170C,301C 'fail':130C 'fall':149C 'fals':459C 'file':63B,161C,251C,275C,330C,354C,366C,448C,451C 'file.separator':454C 'fileoutputstream':457C 'filepath':424C,439C 'fix':193C 'fulli':241C 'furthermor':197C 'gate':218C 'ghsa':14A 'ghsa-78fc':13A 'github.com':86C 'github.com/openmrs/openmrs-core':85C 'impact':88C 'incomplet':125C,406C 'inf':339C 'insid':52B 'instream':460C 'intend':142C,206C,336C 'interfac':216C 'jarentri':400C 'jarfile.entries':397C 'jarfile.getinputstream':461C 'java':33B,394C 'jsp':62B,369C 'latest':79C 'legaci':220C 'load':291C 'malici':249C 'manag':211C 'method':171C 'mod.getmoduleidaspath':436C 'modul':2A,43B,54B,143C,212C,293C 'module.allow':199C 'moduleutil.expandjar':176C 'name':269C,306C,404C,415C 'name.startswith':421C 'name.substring':425C 'new':418C,429C,450C,456C 'normal':182C,441C 'notabl':168C 'omod':109C,250C 'openmr':1A,34B,38B 'openmrs':23A,27A,29A,30A 'openmrs-web':22A,26A 'openmrsutil.copyfi':463C 'org.openmrs.web':21A,25A 'outfil':449C,458C 'outsid':140C,334C 'outstream':455C 'oversight':189C 'packag':35B 'pars':289C 'pass':319C 'path':6A,50B,97C,126C,263C,327C 'paths.get':305C,414C 'payload':265C 'point':224C 'post':91C,229C,277C 'prevent':132C 'proper':179C 'properti':203C,235C 'protect':180C 'rce':382C 'realpath':431C 'remain':326C 'remot':165C 'replac':453C 'reproduc':245C 'rest':39B,226C 'restrict':208C,238C 'root':68B,154C,348C,362C,383C 'run':70B 'runtim':202C 'script':370C 'sequenc':117C,323C 'server':74B,123C,288C,378C 'server-sid':377C 'side':379C 'slip':9A,100C 'start':316C,411C 'startswith':183C,307C,416C,443C 'stay':51B 'step':243C 'string':403C,423C 'stringbuild':427C,430C 'subsequ':164C 'target':148C 'testinstallutil.addzippedtestmodules':177C 'throw':417C 'time':82C 'tomcat':36B 'travers':7A,98C,116C,147C,264C,353C 'trigger':376C 'ui':221C 'unsupportedoperationexcept':419C 'upload':3A,42B,106C,273C 'upon':118C 'valid':127C,280C 'version':76C,77C,80C 'via':213C,283C,373C 'vulner':4A,94C,186C,387C,392C 'w8xw':17A 'web':24A,28A,66B,152C,200C,215C,338C,346C,360C 'web-inf':337C 'web/module':298C,318C,422C 'web/module/../../../..':272C 'web/module/../../../../malicious.jsp':136C 'web/src/main/java/org/openmrs/module/web/webmoduleutil.java':391C 'webmoduleutil.startmodule':129C,295C,390C 'within':150C 'without':47B 'write':60B,162C,447C 'written':139C,333C,365C 'zip':8A,45B,99C,112C,259C 'zip/jar':255C","nicknames":[],"mitigations":[],"who_affected":"Any OpenMRS deployment running `openmrs-web` in the affected ranges where an administrator can upload modules through the REST API. The flaw is in the module upload path, so deployments that do not expose module upload to admins are less exposed. Versions outside the affected ranges are not affected.","tier":"B","verified":{},"analyst_revisit_at":null,"fix_status":"unknown","audience":"businesses","plain_action":null,"pkeys":["openmrs","orgopenmrswebopenmrsweb"],"ptokens":["openmrs","org","web"],"labels":["critical","cwe22","java","maven","openmrs","package","tomcat","vendor"],"campaign_type":null,"search_a":"'-2026':11A,19A '-40076':12A,20A '78fc':15A '9688':16A 'cve':10A,18A 'ghsa':14A 'ghsa-78fc':13A 'modul':2A 'openmr':1A 'openmrs':23A,27A,29A,30A 'openmrs-web':22A,26A 'org.openmrs.web':21A,25A 'path':6A 'slip':9A 'travers':7A 'upload':3A 'vulner':4A 'w8xw':17A 'web':24A,28A 'zip':8A","search_b":"'-22':32B 'applic':67B 'attack':58B 'authent':57B 'check':48B 'code':71B 'cwe':31B 'directori':55B 'endpoint':40B 'entri':46B 'extract':44B 'file':63B 'insid':52B 'java':33B 'jsp':62B 'modul':43B,54B 'openmr':34B,38B 'packag':35B 'path':50B 'rest':39B 'root':68B 'run':70B 'server':74B 'stay':51B 'tomcat':36B 'upload':42B 'web':66B 'without':47B 'write':60B 'zip':45B","search_c":"'/openmrs/openmrs-core':87C '/openmrs/ws/rest/v1/module':92C,230C,278C '/usr/local/tomcat/webapps/openmrs':156C,350C '/view/module':340C,434C '/web-inf':432C '1':246C '11':426C '2':286C '2.7.8':78C '3':351C 'abspath':428C 'abspath.append':433C,435C 'abspath.tostring':452C 'access':357C,371C 'achiev':159C,381C 'admin':201C,281C 'administr':209C 'affect':75C 'allow':236C 'analysi':385C 'api':227C 'append':437C,438C 'appli':196C 'applic':153C,347C,361C 'arbitrari':160C 'archiv':110C,256C 'attack':101C,104C,158C 'auth':285C 'authent':103C 'automat':119C,300C 'basic':284C 'begin':311C 'block':309C,409C 'boundari':444C 'browser':375C 'bypass':242C 'caus':328C,384C 'check':184C,233C,304C,321C,407C,445C 'code':166C,393C 'codebas':175C 'construct':247C 'contain':111C,257C 'control':222C 'craft':108C 'credenti':282C 'directori':115C,144C,341C 'disclosur':84C 'e.g':155C 'endpoint':90C,228C 'entri':113C,133C,223C,260C,268C,296C,310C,315C,396C,401C,410C,462C 'entries.hasmoreelements':399C 'entries.nextelement':402C 'entry.getname':405C 'enumer':395C 'exampl':343C 'execut':167C,380C 'exist':303C,388C 'extract':120C,170C,301C 'fail':130C 'fall':149C 'fals':459C 'file':161C,251C,275C,330C,354C,366C,448C,451C 'file.separator':454C 'fileoutputstream':457C 'filepath':424C,439C 'fix':193C 'fulli':241C 'furthermor':197C 'gate':218C 'github.com':86C 'github.com/openmrs/openmrs-core':85C 'impact':88C 'incomplet':125C,406C 'inf':339C 'instream':460C 'intend':142C,206C,336C 'interfac':216C 'jarentri':400C 'jarfile.entries':397C 'jarfile.getinputstream':461C 'java':394C 'jsp':369C 'latest':79C 'legaci':220C 'load':291C 'malici':249C 'manag':211C 'method':171C 'mod.getmoduleidaspath':436C 'modul':143C,212C,293C 'module.allow':199C 'moduleutil.expandjar':176C 'name':269C,306C,404C,415C 'name.startswith':421C 'name.substring':425C 'new':418C,429C,450C,456C 'normal':182C,441C 'notabl':168C 'omod':109C,250C 'openmrsutil.copyfi':463C 'outfil':449C,458C 'outsid':140C,334C 'outstream':455C 'oversight':189C 'pars':289C 'pass':319C 'path':97C,126C,263C,327C 'paths.get':305C,414C 'payload':265C 'point':224C 'post':91C,229C,277C 'prevent':132C 'proper':179C 'properti':203C,235C 'protect':180C 'rce':382C 'realpath':431C 'remain':326C 'remot':165C 'replac':453C 'reproduc':245C 'rest':226C 'restrict':208C,238C 'root':154C,348C,362C,383C 'runtim':202C 'script':370C 'sequenc':117C,323C 'server':123C,288C,378C 'server-sid':377C 'side':379C 'slip':100C 'start':316C,411C 'startswith':183C,307C,416C,443C 'step':243C 'string':403C,423C 'stringbuild':427C,430C 'subsequ':164C 'target':148C 'testinstallutil.addzippedtestmodules':177C 'throw':417C 'time':82C 'travers':98C,116C,147C,264C,353C 'trigger':376C 'ui':221C 'unsupportedoperationexcept':419C 'upload':106C,273C 'upon':118C 'valid':127C,280C 'version':76C,77C,80C 'via':213C,283C,373C 'vulner':94C,186C,387C,392C 'web':152C,200C,215C,338C,346C,360C 'web-inf':337C 'web/module':298C,318C,422C 'web/module/../../../..':272C 'web/module/../../../../malicious.jsp':136C 'web/src/main/java/org/openmrs/module/web/webmoduleutil.java':391C 'webmoduleutil.startmodule':129C,295C,390C 'within':150C 'write':162C,447C 'written':139C,333C,365C 'zip':99C,112C,259C 'zip/jar':255C","cause_entry":null,"cause_path":null,"disclosures_checked_at":null,"first_public_at":"2026-05-04T15:11:45+00:00","kev":null,"cvss_vector":"CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:C/C:H/I:H/A:N","cvss_by":"GitHub","poc_count":0,"sources":[{"source":"ghsa","external_id":"GHSA-78fc-9688-w8xw","url":"https://github.com/advisories/GHSA-78fc-9688-w8xw","severity":"critical","published_at":"2026-05-04T17:39:31+00:00","modified_at":"2026-11-12T18:15:39+00:00","first_seen_at":"2026-11-12T18:20:03+00:00","fetched_at":"2026-11-12T18:25:53+00:00","note":null},{"source":"nvd","external_id":"CVE-2026-40076","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-40076","severity":null,"published_at":"2026-05-06T20:16:31+00:00","modified_at":"2026-10-26T19:10:00+00:00","first_seen_at":"2026-11-12T18:40:39+00:00","fetched_at":"2026-11-12T18:40:39+00:00","note":null}],"documents":[{"id":137250,"url":"https://api.github.com/repos/openmrs/openmrs-core/security-advisories/GHSA-78fc-9688-w8xw","title":"Maintainer's advisory: api.github.com","kind":"vendor","source":"ghsa","publisher":"vendor","text":null,"published_at":null,"relation":"advisory","confidence":null,"note":"Maintainer's advisory: api.github.com"},{"id":137251,"url":"https://github.com/openmrs/openmrs-core/security/advisories/GHSA-78fc-9688-w8xw","title":"Maintainer's advisory: github.com","kind":"vendor","source":"ghsa","publisher":"vendor","text":null,"published_at":"2026-05-04T15:11:45+00:00","relation":"advisory","confidence":null,"note":"Maintainer's advisory: github.com"}],"disclosures":[],"exploit_sources":[{"type":"epss","score":0.00853,"url":"https://api.first.org/data/v1/epss?cve=CVE-2026-40076"}],"notice":"Free to read, with fair use of about 60 pages a minute. For higher limits or API access: sales@infrastack.ai"}