/

CVE-2026-59194

Severity:

HIGH RISK

(7.1)

Path Traversal (CWE-22) in pnpm Patch Removal Feature

CVE-2026-59194

Analyzed

Vulnerability type

Category:

Path Traversal

CWE:

CWE-22, CWE-73

Impact:

Arbitrary File Deletion

Severity:

HIGH RISK

(7.1)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

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-remove on 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.

Sources

SourceLink
github.comgithub.com/pnpm/pnpm/security/advisories/GHSA-72r4-9c5j-mj57

Frequently asked

questions

Exploitability depends on who can influence pnpm patch entries or configuration. In environments where patches come from shared or untrusted sources, an attacker could cause pnpm patch-remove to delete unintended files; in tightly controlled setups, the risk is lower.

An attacker needs the ability to create or modify patch entries that pnpm will later process—this could be commit access to a repository, control over a shared patch source, or influence over tooling that generates patch metadata.

The safest pattern is to canonicalize and strictly validate all paths used by patch operations, ensuring they remain within a designated patches directory and rejecting any entries that attempt to navigate outside or use disallowed constructs.

Future designs should treat all file paths as untrusted, enforce directory confinement checks, apply least-privilege to file operations, and incorporate security-focused code review and automated checks for path traversal and externally controlled paths.

Find out what's already
exploitable in your codebase.