Summary
A path traversal issue in pnpm's handling of transitive dependency aliases allows crafted registry metadata to inject filesystem paths outside the intended node modules tree.
When pnpm install --ignore-scripts processes these aliases, it can replace paths inside the current project with symlinks pointing to attacker-controlled package directories, exposing project files to malicious modification.
Affected context
This vulnerability appears in environments using pnpm as the package manager where:
- Dependencies are fetched from registries that can provide or proxy package metadata
- Transitive dependencies define aliases that pnpm later interprets as filesystem paths
- Projects rely on
pnpm install(including--ignore-scripts) to manage their dependency tree
Under these conditions, path traversal segments embedded within dependency aliases may affect the layout of files and directories within the project.
Exploit preconditions
- Attack surface: The dependency resolution and install process in pnpm, driven by registry-provided package metadata.
- Required access: Ability to publish or influence a registry package that will be installed as a dependency, including control over its alias metadata.
- Trigger point: Running
pnpm install, particularly with--ignore-scripts, causing pnpm to interpret the malicious alias value as a filesystem path during symlink creation. - Why exploitation is possible: pnpm does not sufficiently sanitize or constrain path components in dependency aliases, allowing traversal sequences (e.g.,
../) to affect where symlinks are created within the project directory.
Why this happens
The root cause is insufficient validation of user-controlled path components derived from package metadata before they are used for filesystem operations.
Alias fields in transitive dependencies are treated as trusted paths and incorporated into pnpm's linking logic without normalization checks, canonicalization, or enforcement of a safe root directory.
This maps to CWE-23: Relative Path Traversal, where untrusted input is used to construct relative paths, enabling navigation outside the expected directory boundaries and unintended modification of filesystem locations.
Potential impact
- Project files and directories may be replaced with symlinks to attacker-controlled package contents.
- Build artifacts or configuration files could be redirected to malicious resources, affecting application behavior.
- Sensitive project files can be exposed indirectly if tools follow attacker-created symlinks.
- Local development or CI environments could be destabilized by unexpected path changes and corrupted dependency graphs.
General mitigation guidance
Effective mitigation focuses on constraining how metadata-derived paths are interpreted and used during dependency installation.
Pattern-based defenses include:
- Normalizing and validating all path-like metadata fields (such as aliases) before using them in filesystem operations.
- Enforcing a strict, designated root directory for dependency links and rejecting paths that attempt traversal outside this boundary.
- Treating registry metadata as untrusted input, reducing implied trust of fields that influence filesystem layout.
- Applying least-privilege principles to build and install environments so that package managers operate in isolated directories with limited impact on surrounding project structures.
- Introducing safe defaults that ignore or sanitize aliases containing suspicious components rather than relying on consumers to configure protections.
How teams detect issues like this
High-level strategies to detect similar vulnerabilities and misuse include:
- Static analysis or internal audits of package manager code paths that construct filesystem paths from external metadata or user input.
- Code review practices that flag any use of relative paths derived from untrusted sources, particularly where traversal segments are not explicitly filtered.
- Policy-based checks in CI pipelines that inspect dependency metadata for unusual alias values or patterns suggesting path traversal.
- Monitoring for unexpected symlink creation or directory changes in project workspaces during dependency installation, potentially aided by integrity checks or filesystem snapshots.

