/

CVE-2026-50015

Severity:

HIGH RISK

(7.3)

Path Traversal (CWE-22) in pnpm Patch Application

CVE-2026-50015

Analyzed

Vulnerability type

Category:

Path Traversal

CWE:

CWE-22

Impact:

Arbitrary File Write and Deletion

Severity:

HIGH RISK

(7.3)

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

The pnpm patch application pipeline trusts file paths embedded in .patch files without validating whether they stay within the intended package directory.

When a malicious contributor adds a crafted patch to a project, running pnpm install can overwrite or delete arbitrary files on the filesystem as the installing user, making code review alone insufficient to catch the issue.

Affected context

This vulnerability appears in development and CI environments that use pnpm's patch-package functionality to apply .patch files during pnpm install.

It becomes relevant when projects accept patches from contributors, store them in version control, and treat them as trusted input.

The risk is higher in repositories where reviewers do not closely inspect patch file headers, and where installs run with broad filesystem access on developer machines or CI runners.

Exploit preconditions

  • Attack surface: The patch application pipeline invoked as part of pnpm install.
  • Required access: Ability to submit or modify .patch files in the project (e.g., via pull requests or direct repository access).
  • Trigger point: Execution of pnpm install on a codebase that includes the malicious patch.
  • Why exploitation is possible: The implementation does not validate or constrain paths in the diff --git headers, allowing ../../ segments to escape the package directory and target arbitrary locations.

Why this happens

The underlying issue is a path traversal bug consistent with CWE-22: Improper Limitation of a Pathname to a Restricted Directory.

pnpm's patch application logic uses file paths extracted from .patch files as-is, assuming they remain within the package directory.

Without normalization, canonicalization, and enforcement of a strict base directory, ../../ sequences in patch headers allow attackers to navigate outside the intended scope and perform file operations on arbitrary paths.

Potential impact

  • Attacker-controlled content may overwrite files outside the package directory.
  • Local configuration or source files could be deleted, disrupting builds or development environments.
  • Sensitive project assets (scripts, hooks, configs) can be modified to introduce further compromise.
  • CI/CD environments can be destabilized or prepared for follow-on attacks via tampered files.

General mitigation guidance

Effective mitigation focuses on constraining patch file handling to a well-defined directory and treating patch paths as untrusted input.

Common patterns include:

  • Normalizing and canonicalizing patch paths, then enforcing that they resolve under a single trusted base directory.
  • Rejecting or ignoring any file path containing directory traversal segments or absolute paths.
  • Reducing the trust level of contributed patch files and minimizing automatic execution of file modifications from third-party contributions.
  • Running dependency and patch processing with least-privilege filesystem access so that unintended writes are limited in scope.

How teams detect issues like this

High-level detection approaches may include:

  • Static analysis or custom linters that scan .patch files for suspicious ../../ segments or absolute paths in diff --git headers.
  • Code review guidelines that explicitly call out patch files as high-risk inputs and require checking path scopes.
  • Repository policies that restrict who can add or modify patch files, combined with automated checks on pull requests.
  • File-system activity monitoring in CI environments to flag unexpected writes outside designated project directories during pnpm install.

Sources

SourceLink
github.comgithub.com/pnpm/pnpm/security/advisories/GHSA-rxhj-4m44-96r4

Frequently asked

questions

Exploitation is typically limited to scenarios where attackers can contribute patch files to a project, such as through pull requests or compromised accounts, but any environment that runs pnpm install on those patches can be affected.

The attacker needs write access to the repository or contribution channel used for storing .patch files, enabling them to insert malicious paths that will be applied during installation.

The safest approach is to strictly validate and normalize all patch paths, enforcing that they remain inside a designated directory and rejecting any path containing directory traversal or absolute segments.

Treat all filesystem-related inputs, including patch files, as untrusted; enforce strong path validation in tooling, run build and install steps with minimal privileges, and incorporate automated checks on contributed artifacts in your CI pipeline.

Find out what's already
exploitable in your codebase.