{"id":"CVE-2025-59342","aliases":["CVE-2025-59342","GHSA-g2h5-cvvr-7gmw","GO-2025-3967"],"related":[],"kind":"vulnerability","state":"published","title":"esm.sh writes arbitrary files via path traversal in `X-Zone-Id` header","summary":"esm.sh is a nobuild content delivery network(CDN) for modern web development. In 136 and earlier, a path-traversal flaw in the handling of the X-Zone-Id HTTP header allows an attacker to cause the application to write files outside the intended storage location. The header value is used to build a filesystem path but is not properly canonicalized or restricted to the application’s storage base directory. As a result, supplying ../ sequences in X-Zone-Id causes files to be written to arbitrary directories. Version 136.1 contains a patch.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"esm.sh is a nobuild content delivery network(CDN) for modern web development. In 136 and earlier, a path-traversal flaw in the handling of the X-Zone-Id HTTP header allows an attacker to cause the application to write files outside the intended storage location. The header value is used to build a filesystem path but is not properly canonicalized or restricted to the application’s storage base directory. As a result, supplying ../ sequences in X-Zone-Id causes files to be written to arbitrary directories. Version 136.1 contains a patch.","source":"cvelist"},{"lang":"en","text":"## Summary\n\nA path-traversal flaw in the handling of the `X-Zone-Id` HTTP header allows an attacker to cause the application to write files outside the intended storage location. The header value is used to build a filesystem path but is not properly canonicalized or restricted to the application’s storage base directory. As a result, supplying `../` sequences in `X-Zone-Id` causes files to be written to arbitrary directories (example observed: `~/.esmd/modules/transform/<id>/` instead of `~/.esmd/storage/modules/transform`).\n\n**Severity:** Medium\n\n**Component / Endpoint:** \n\n`POST /transform` — handling of `X-Zone-Id` header\n\nThe vulnerable code is in https://github.com/esm-dev/esm.sh/blob/main/server/router.go#L116 and https://github.com/esm-dev/esm.sh/blob/main/server/router.go#L411 \n\n**Impact:** Arbitrary file creation / overwrite outside intended storage directory (file write to attacker-controlled path). Possible remote code execution, persistence, tampering with application files, or facilitating further path-traversal attacks.\n\n---\n\n## Proof of Concept (POC)\n\nRequest (attacker-supplied `X-Zone-Id` contains path traversal):\n\n```\nPOST /transform HTTP/1.1\nHost: localhost:8888\nUser-Agent: Den/8.7.1\nAccept: */*\nConnection: keep-alive\nReferer: http://localhost:9999/\nContent-Type: application/json\nX-Zone-Id: ../../modules/transform/c245626ef6ca0fd9ee37759c5fac606c6ec99daa/\nContent-Length: 325\n\n{\n  \"filename\": \"example2.js\",\n  \"lang\": \"js\",\n  \"code\": \"console.log('hello');\",\n  \"importMap\": {\n    \"imports\": {\n      \"react\": \"https://esm.sh/react\",\n      \"react-dom\": \"https://esm.sh/react-dom\"\n    }\n  },\n  \"jsxImportSource\": \"react\",\n  \"target\": \"es2022\",\n  \"sourceMap\": \"external\",\n  \"minify\": true\n}\n```\n<img width=\"2496\" height=\"1214\" alt=\"Screenshot 2025-09-16 at 21 40 57\" src=\"https://github.com/user-attachments/assets/f878c3f0-5d7d-410c-97ac-20116f5496db\" />\n\n\nObserved result: file written to `~/.esmd/modules/transform/c245626ef6ca0fd9ee37759c5fac606c6ec99daa/example2.js` instead of the intended `~/.esmd/storage/modules/transform/`.\n\nThis can be trigger with another path traversal request below\n\n```\nGET /+c245626ef6ca0fd9ee37759c5fac606c6ec99daa./../../../esm.db?.css HTTP/1.1\nHost: localhost:8888\nUser-Agent: localhost\nAccept: */*\nConnection: keep-alive\nX-Zone-Id: ../\nReferer: http://localhost:9999/\n\n```\n<img width=\"2516\" height=\"710\" alt=\"Screenshot 2025-09-16 at 21 37 07\" src=\"https://github.com/user-attachments/assets/1fcfbed3-c1d2-4093-82d8-4afda225c685\" />\n\n---\n\n## Remediation\n\nSimply remove any .. in the `X-Zone-Id` header before actually process the file.\n\n## Credits\n\n- [Ai Ho (Jessie)](https://github.com/j3ssie)\n- [CL Yang](https://github.com/A11riseforme)","format":"markdown","source":"ghsa"},{"lang":"en","text":"esm.sh has arbitrary file write via path traversal in `X-Zone-Id` header in github.com/esm-dev/esm.sh","format":"markdown","source":"go"},{"lang":"es","text":"esm.sh es una red de entrega de contenido (CDN) sin compilación para el desarrollo web moderno. En 136 y anteriores, una falla de path traversal en el manejo del encabezado HTTP X-Zone-Id permite a un atacante hacer que la aplicación escriba archivos fuera de la ubicación de almacenamiento prevista. El valor del encabezado se utiliza para construir una ruta del sistema de archivos, pero no se canonicaliza correctamente ni se restringe al directorio base de almacenamiento de la aplicación. Como resultado, suministrar secuencias ../ en X-Zone-Id hace que los archivos se escriban en directorios arbitrarios.","source":"nvd"}],"published":"2025-09-17T17:59:34.163Z","modified":"2026-09-10T03:50:28.407Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:L/VA:N/SC:N/SI:N/SA:N/E:P","score":5.5,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:L/VA:N/SC:N/SI:N/SA:N/E:P","score":5.5,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:L/VA:N/SC:N/SI:N/SA:N/E:P","rating":"MEDIUM"}],"cwes":["CWE-24"],"affected":[{"ranges":[{"version":"<= 136","status":"affected"}],"vendor":"esm-dev","product":"esm.sh","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"136.1"}],"ecosystem":"Go","package":"github.com/esm-dev/esm.sh","purl":"pkg:golang/github.com/esm-dev/esm.sh","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"0","status":"affected"}],"ecosystem":"Go","package":"github.com/esm-dev/esm.sh","purl":"pkg:golang/github.com/esm-dev/esm.sh","source":"go"}],"references":[{"url":"https://github.com/esm-dev/esm.sh/security/advisories/GHSA-g2h5-cvvr-7gmw","tags":["advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","go","nvd"]},{"url":"https://github.com/esm-dev/esm.sh/commit/833a29f42aeb0acbd7089a71be11dd0a292d3151","tags":["fix","web","x-refsource-misc"],"sources":["cvelist","ghsa","go","nvd"]},{"url":"https://github.com/esm-dev/esm.sh/blob/main/server/router.go#L116","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","go","nvd"]},{"url":"https://github.com/esm-dev/esm.sh/blob/main/server/router.go#L411","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","go","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2025-59342","tags":["advisory"],"sources":["ghsa","go"]},{"url":"https://github.com/esm-dev/esm.sh","tags":["package"],"sources":["ghsa"]},{"url":"https://pkg.go.dev/vuln/GO-2025-3967","tags":["web"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"yes","technicalImpact":"partial","date":"2025-09-17T18:19:55.260Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2025-59342","url":"https://www.cve.org/CVERecord?id=CVE-2025-59342","licence":"CVE Terms of Use","modified":"2026-01-14T15:52:09.174Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-g2h5-cvvr-7gmw","url":"https://github.com/advisories/GHSA-g2h5-cvvr-7gmw","licence":"CC-BY-4.0","modified":"2026-09-10T03:50:28.407Z"},{"source":"go","name":"Go Vulnerability Database","id":"GO-2025-3967","url":"https://pkg.go.dev/vuln/GO-2025-3967","licence":"CC-BY-4.0","modified":"2026-03-03T04:56:55.361Z"},{"source":"nvd","name":"NVD","id":"CVE-2025-59342","url":"https://nvd.nist.gov/vuln/detail/CVE-2025-59342","licence":"Public domain","modified":"2026-06-17T09:45:56.447Z"}],"updatedAt":"2026-11-25T22:59:04.794Z","epss":{"score":0.03284,"percentile":0.88802,"date":"2026-12-02T12:00:21.000Z"}}