esm.sh has arbitrary file write via path traversal in `X-Zone-Id` header
Date: 2025-09
Affected: go/github.com/esm-dev/esm.sh
Attack vector: path-traversal
Category: vulnerability-disclosure
Severity: Medium
CVE: CVE-2025-59342
CWE: CWE-24

## 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');",


Mitigations:

Architectural layers (MAESTRO):