Summary
A path traversal vulnerability in pnpm allows a crafted tarball dependency to provide a scoped package name containing path separators. During installation, the unvalidated name can direct extracted files outside the intended node_modules directory, potentially overwriting attacker-selected files and enabling code execution.
Affected context
The vulnerability occurs during pnpm installation of a tarball dependency when its package.json manifest contains a scoped name with traversal-related path components. The issue is relevant when the package is processed by affected dependency-resolution and extraction logic, including installations performed with --ignore-scripts, because the unsafe path handling occurs independently of lifecycle script execution.
Exploit preconditions
- Attack surface: Dependency installation and package extraction
- Required access: Ability to cause a victim project or build environment to install a crafted tarball dependency
- Trigger point: Dependency graph resolution and extraction of the package during
pnpm install - Why exploitation is possible: Scoped package names are insufficiently validated before reaching filesystem path joins, allowing extraction paths to escape the intended dependency directory
Why this happens
The underlying bug is inconsistent validation of package names. The resolver rejects slash characters for unscoped names but permits them in scoped names, allowing a package manifest to carry path traversal components into later path-construction logic.
This maps primarily to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, because attacker-controlled path data can escape the expected extraction root. It is also related to CWE-73: External Control of File Name or Path and may result in CWE-94: Improper Control of Generation of Code, when overwritten files are later executed.
Potential impact
- Arbitrary files outside
node_modulesmay be overwritten - Shell startup files or Git hooks could be modified
- Installed package code or build inputs may be replaced
- Continuous integration environments could be compromised
- Subsequent commands may execute attacker-controlled code
- Build integrity, source repositories, or developer workstations could be affected
General mitigation guidance
Mitigation generally focuses on treating package metadata as untrusted input and enforcing a single, canonical extraction boundary.
Common defensive patterns include:
- Validate package names and derived paths consistently for both scoped and unscoped packages
- Reject path separators, traversal components, absolute paths, and other non-canonical path forms
- Resolve candidate paths and verify that they remain beneath the intended extraction directory
- Use secure archive extraction routines that enforce destination containment
- Apply least privilege to package-manager, build, and CI processes
- Separate dependency installation from sensitive host paths and credentials
- Use lockfiles, trusted registries, dependency review, and artifact integrity controls to reduce malicious-package exposure
- Treat
--ignore-scriptsas insufficient protection against filesystem-based package extraction flaws
How teams detect issues like this
Organizations can look for this class of issue through:
- Static analysis of package-name validation and filesystem path-join logic
- Code review checks for user-controlled values passed to archive extraction or path construction
- Tests covering scoped names, separators, traversal components, absolute paths, and platform-specific path syntax
- Runtime monitoring for package-manager writes outside approved dependency directories
- File-integrity monitoring for unexpected changes to Git hooks, shell profiles, build scripts, and installed package files
- Dependency policies that require approved registries, provenance, and review of tarball contents
- Automated security review tools that flag archive extraction and path-containment weaknesses

