Summary
A path traversal flaw in pnpm's patch removal logic allows a crafted patch entry to resolve outside the intended patches directory.
When triggered, pnpm patch-remove can delete arbitrary reachable files on the system, making environments that apply user-influenced patches particularly at risk.
Affected context
This vulnerability appears in environments using pnpm's patch management feature, specifically the patch-remove command.
It becomes relevant when patch entries are stored or generated in a way that could be influenced by external inputs, such as shared repositories, tooling-generated patches, or team-wide configuration files.
The issue arises when the patch metadata contains paths that pnpm treats as valid patch locations without enforcing strict confinement to the configured patches directory.
Exploit preconditions
- Attack surface: pnpm CLI execution context, typically developer workstations, CI agents, or build servers using
pnpm patch-remove. - Required access: Ability to create or modify patch entries or configuration files consumed by pnpm's patch feature.
- Trigger point: Running
pnpm patch-removeon a patch entry containing a maliciously crafted path that resolves outside the patches directory. - Why exploitation is possible: The patch removal logic fails to robustly validate that resolved paths remain inside the configured patches directory, enabling path traversal that targets arbitrary files.
Why this happens
The core issue is insufficient path normalization and validation in the code that interprets patch entries, mapping directly to CWE-22: Improper Limitation of a Pathname to a Restricted Directory.
pnpm's patch removal logic relies on user-supplied or configuration-derived paths and assumes they reference files located in a designated patches directory.
Without enforcing a strict directory boundary—such as rejecting relative segments (../) or symbolic link redirections—paths can traverse outside the intended directory.
This insecure pattern is further related to CWE-73: External Control of File Name or Path, because the file paths influencing deletion behavior are effectively controlled by external inputs rather than being internally constrained.
Potential impact
- Deletion of arbitrary files reachable by the pnpm process.
- Loss of source code, configuration files, or build artifacts.
- Corruption of development or CI environments, disrupting builds and deployments.
- Potential weakening of security posture if critical security-related files are removed.
General mitigation guidance
Effective mitigation centers on treating file and path parameters as untrusted input and constraining them to a well-defined directory boundary.
Common defensive patterns include:
- Canonicalizing paths and verifying they reside within the configured patches directory before performing file operations.
- Rejecting any patch metadata that contains disallowed path components (such as
.., absolute paths, or unexpected symbolic link targets). - Applying least-privilege to pnpm execution environments so that file deletion operations are limited in scope and impact.
- Isolating patch-related operations (e.g., in sandboxed workspaces or containers) to minimize consequences if path validation fails.
How teams detect issues like this
Detection can focus on both code-level and operational signals:
- Static analysis rules and code review checklists that flag any file deletion or mutation logic using externally controlled paths without directory boundary checks.
- Policy-based enforcement in repositories to inspect patch metadata and configuration files for suspicious or out-of-root paths before they are committed or consumed.
- Runtime monitoring or audit logging of pnpm executions that delete files outside expected patch locations, enabling investigation of anomalous deletions.
- Integration of automated security review tools in CI pipelines to highlight path traversal patterns and unvalidated filesystem access in supporting scripts or tooling.

