Summary
A path traversal vulnerability in pnpm's stage download command allowed registry-controlled package metadata to influence local filenames.
Under certain conditions, a crafted package manifest could escape the intended download directory and overwrite other reachable files, posing a risk to systems that consume untrusted packages.
Affected context
This vulnerability arises when pnpm is used to download packages whose manifest fields (such as name and version) are not fully trusted or validated.
It specifically impacts workflows invoking pnpm stage download, where the local destination path is derived from registry-supplied metadata. The issue is more significant in environments that process third-party or community packages at scale, or where pnpm runs with elevated file system privileges and has access to sensitive directories.
Exploit preconditions
- Attack surface: Package ingestion pipeline using
pnpm stage downloadand reading manifests from a remote registry or other untrusted source. - Required access: Ability to publish or modify package manifests (including name and version) that pnpm will download, or control a registry that feeds pnpm.
- Trigger point: Execution of
pnpm stage downloadon a crafted package; the tool computes a filesystem path using unvalidated name/version fields and writes the downloaded contents. - Why exploitation is possible: The code trusted the package metadata when constructing local filenames, without enforcing strict normalization or validating the resolved path against the intended download directory, so traversal sequences could redirect writes to unintended locations.
Why this happens
The underlying bug is a classic path traversal issue mapped to CWE-22 and related to external control of file names or paths (CWE-73). The implementation derived a local filename directly from registry-controlled fields (package name and version) and then used that filename to form the destination path.
Without robust validation, sanitization, or enforcement that the final resolved path remained under the designated download directory, malicious metadata could include directory traversal tokens or crafted patterns. This allowed an attacker-controlled manifest to influence where files were written, breaking assumptions about the isolation of the download directory and enabling overwrite of other reachable files on the host.
Potential impact
- An attacker-controlled package may overwrite arbitrary files reachable by the pnpm process within the same filesystem hierarchy.
- Critical configuration or script files used by build or deployment tooling could be replaced, potentially altering subsequent execution flows.
- Local cache or lock files may be corrupted, leading to subtle supply-chain manipulation or denial of service in CI/CD pipelines.
- In environments where pnpm runs with elevated privileges, file overwrites may facilitate further compromise depending on what files can be targeted.
General mitigation guidance
Effective mitigation focuses on decoupling untrusted metadata from filesystem paths and enforcing strict path safety checks.
General patterns include:
- Deriving local filenames from controlled, normalized identifiers rather than directly from registry-supplied fields.
- Validating and sanitizing any path components influenced by external input, rejecting traversal sequences and illegal characters.
- Verifying that the final resolved destination path is still inside the intended working or download directory before performing write operations.
- Running package management and build tooling with least privilege, limiting the set of directories they can modify.
- Incorporating defense-in-depth controls such as filesystem permissions and sandboxing to reduce the impact of any path-related flaw.
How teams detect issues like this
High-level detection approaches for similar vulnerabilities include:
- Static analysis rules that flag uses of untrusted input in path construction, especially when combined with file write operations.
- Code review practices that look for direct concatenation of user or registry-supplied strings into filenames or directory paths, and verify that canonicalization checks are in place.
- Security policies that require normalization and boundary validation (e.g., ensuring paths remain under a specific root) for any file operation derived from external data.
- Automated tooling—such as secure coding linters or SAST platforms—configured to detect CWE-22 and CWE-73 patterns in build and package management codebases.

