Skip to content

fix(security): backport lockfile & manifest name/slot containment to v10 - #12890

Merged
zkochan merged 1 commit into
release/10from
release/v10-backport-sec-fixes
Jul 9, 2026
Merged

zkochan merged 1 commit into
release/10from
release/v10-backport-sec-fixes

Conversation

@zkochan

@zkochan zkochan commented Jul 9, 2026

Copy link
Copy Markdown
Member

Backports the TypeScript portion of 51300fd (#12872) to release/10, covering two advisories:

  • GHSA-c59q-g84q-2gj5: a crafted pnpm-lock.yaml whose packages depPath key carries a path-traversal name (e.g. ../../../tmp/[email protected]) could make the isolated (virtual-store) linker and the Plug'n'Play resolver map write/point outside the virtual store.
  • GHSA-vq4v-j7r6-jq4m: a dependency whose manifest name is a scoped path traversal (e.g. @x/../../../<path>) could be written outside node_modules during pnpm install, even with --ignore-scripts.

Changes (mapped from the pnpm11/ layout to v10)

main (pnpm11) v10
deps/graph-builder lockfileToDepGraph deps/graph-builder/src/lockfileToDepGraph.ts — safeJoinModulesDir at the name join
deps/graph-hasher formatGlobalVirtualStorePath packages/calc-dep-state iterateHashedGraphNodes — reject a traversal version segment at the single point every global-virtual-store slot path funnels through
installing/deps-resolver (extendGraph, resolvePeers) pkg-manager/resolve-dependencies src/index.ts + src/resolvePeers.ts — safeJoinModulesDir at both name joins
lockfile/to-pnp lockfile/lockfile-to-pnp — contain the PnP packageLocation

Not applicable to v10: the pacquet (Rust) changes, and the env-installer/installOptionalSubdeps guards (v10's installConfigDeps has no global-virtual-store subdep installation, and config-dependency names are already validated by assertValidConfigDepName from #12504).

All rejections surface ERR_PNPM_INVALID_DEPENDENCY_NAME, matching main.

Tests

  • Ported the crafted-lockfile tests to deps/graph-builder (new test suite: traversal/reserved names, no directory created outside the store, GVS version-segment escape).
  • Ported the GVS version-segment rejection tests to calc-dep-state (iterateHashedGraphNodes).
  • Ported the PnP registry rejection test to lockfile-to-pnp.
  • Ported the end-to-end tarball test (pkg-with-path-traversal-name.tgz fixture) to @pnpm/core.
  • All new and existing tests of the touched packages pass, including @pnpm/core global-virtual-store install tests.

🤖 Generated with Claude Code

Backports the TypeScript portion of 51300fd (#12872) to release/10.
Two advisories:

- GHSA-c59q-g84q-2gj5: lockfile depPath name -> isolated linker + PnP.
- GHSA-vq4v-j7r6-jq4m: dependency manifest `name` from the fetched
  tarball (e.g. @x/../../../path) -> resolver/linker.

Apply safeJoinModulesDir at lockfileToDepGraph (deps/graph-builder) and
the PnP packageLocation (lockfile-to-pnp); validate manifest names in
resolve-dependencies (extendGraph + resolvePeers); contain the
global-virtual-store slot dir by rejecting a traversal version segment
in iterateHashedGraphNodes (calc-dep-state), the single point every GVS
slot path funnels through.

The pacquet and env-installer changes from the original commit do not
apply to v10 (no pacquet stack; installConfigDeps has no GVS subdep
installation and config-dependency names are already validated by
assertValidConfigDepName from #12504).

All rejections surface ERR_PNPM_INVALID_DEPENDENCY_NAME.

Co-Authored-By: Claude Fable 5 <[email protected]>
Copilot AI review requested due to automatic review settings July 9, 2026 22:56
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 92c3ef8c-e0a2-4770-9d25-d0124ea3b5e1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch release/v10-backport-sec-fixes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

fix(security): contain traversal names/slots from lockfile & manifests (v10)

🐞 Bug fix 🧪 Tests 📝 Documentation ⚙️ Configuration changes 🕐 40+ Minutes

Grey Divider

AI Description

• Reject lockfile-derived package names that could escape the virtual store or PnP map.
• Reject global-virtual-store slot paths whose lockfile-controlled version segment contains
 traversal.
• Add regression tests and backport changesets/deps to release/v10.
Diagram

graph TD
  L["pnpm-lock.yaml (untrusted)"] --> GB["deps/graph-builder"] --> SJ["safeJoinModulesDir"] --> VS[("Virtual store")]
  L --> RD["resolve-dependencies"] --> SJ
  GB --> HS["iterateHashedGraphNodes"] --> VS
  L --> PNP["lockfile-to-pnp"] --> SJ
  PNP --> MAP[".pnp.cjs registry"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Validate at lockfile parse/normalization time
  • ➕ Centralizes trust-boundary checks early; fewer downstream sinks to harden
  • ➕ Could reject malformed depPath/version once for all consumers
  • ➖ Higher backport risk: touches core lockfile parsing and may break edge-case lockfiles
  • ➖ Harder to ensure all derived paths (including PnP/GVS) are covered without duplicating logic
2. Avoid reconstructing package names from depPath keys where possible
  • ➕ Reduces reliance on attacker-controlled name components altogether
  • ➕ Potentially simplifies containment logic for virtual-store joins
  • ➖ Requires broader refactors across graph builders/resolvers (not ideal for a v10 security backport)
  • ➖ May still need name validation for manifests/tarballs and other call sites

Recommendation: Current approach is the right v10 backport strategy: harden the concrete filesystem/path sinks (virtual-store directory joins and PnP packageLocation) by reusing the existing safeJoinModulesDir guard, and add a single choke-point rejection for the lockfile-controlled GVS version segment in iterateHashedGraphNodes. This minimizes behavioral surface area while directly addressing both advisories and aligns errors to ERR_PNPM_INVALID_DEPENDENCY_NAME.

Files changed (19) +292 / -10

Bug fix (5) +36 / -8
lockfileToDepGraph.tsContain lockfile-derived package dir join in virtual store +6/-1

Contain lockfile-derived package dir join in virtual store

• Uses safeJoinModulesDir when joining the lockfile-reconstructed pkgName under the virtual store's node_modules directory. Prevents traversal/reserved names from escaping the virtual store and aligns behavior with the hoisted linker.

deps/graph-builder/src/lockfileToDepGraph.ts

index.tsContain PnP packageLocation against lockfile name traversal +9/-5

Contain PnP packageLocation against lockfile name traversal

• Builds the packageLocation by joining name onto the virtual store via safeJoinModulesDir instead of raw path.join. Prevents crafted lockfile depPath names from making .pnp.cjs point outside the virtual store.

lockfile/lockfile-to-pnp/src/index.ts

index.tsReject traversal in global-virtual-store version path segment +17/-0

Reject traversal in global-virtual-store version path segment

• Adds assertNoPathTraversal(version) inside iterateHashedGraphNodes before constructing the @/name/version/hash slot path. Throws ERR_PNPM_INVALID_DEPENDENCY_NAME when version contains '..' segments to prevent escaping the GVS root.

packages/calc-dep-state/src/index.ts

index.tsUse safeJoinModulesDir when extending graph node directories +2/-1

Use safeJoinModulesDir when extending graph node directories

• Replaces raw path.join(modules, node.name) with safeJoinModulesDir to validate and contain the resolved manifest/package name. Prevents writing outside virtual store via crafted manifest names.

pkg-manager/resolve-dependencies/src/index.ts

resolvePeers.tsContain peer-resolution virtual-store directory join +2/-1

Contain peer-resolution virtual-store directory join

• Uses safeJoinModulesDir when deriving a resolved peer package's directory under the virtual store. Ensures peer resolution cannot introduce traversal/reserved directory names.

pkg-manager/resolve-dependencies/src/resolvePeers.ts

Tests (4) +200 / -0
lockfileToDepGraph.test.tsAdd crafted-lockfile traversal/reserved-name regression tests +120/-0

Add crafted-lockfile traversal/reserved-name regression tests

• Introduces tests that feed crafted lockfile depPath keys and assert ERR_PNPM_INVALID_DEPENDENCY_NAME. Verifies no directory is created outside the virtual store and covers GVS version-segment escape cases.

deps/graph-builder/test/lockfileToDepGraph.test.ts

index.tsAdd PnP rejection test for traversal package name in lockfile +32/-0

Add PnP rejection test for traversal package name in lockfile

• Adds a regression test that constructs a lockfile with a traversal depPath key name and asserts ERR_PNPM_INVALID_DEPENDENCY_NAME. Ensures PnP registry generation rejects the malicious entry.

lockfile/lockfile-to-pnp/test/index.ts

iterateHashedGraphNodes.test.tsAdd tests for GVS slot hashing and version traversal rejection +34/-0

Add tests for GVS slot hashing and version traversal rejection

• Validates the normal hash path format and adds parameterized cases where version contains traversal. Asserts ERR_PNPM_INVALID_DEPENDENCY_NAME is thrown for the traversal inputs.

packages/calc-dep-state/test/iterateHashedGraphNodes.test.ts

fromTarball.tsAdd e2e tarball test for manifest-name traversal rejection +14/-0

Add e2e tarball test for manifest-name traversal rejection

• Uses a tarball fixture whose manifest name is a scoped traversal and asserts install is rejected. Covers the manifest-name vulnerability path through core dependency installation.

pkg-manager/core/test/install/fromTarball.ts

Documentation (2) +15 / -0
contain-virtual-store-package-name.mdAdd changeset for lockfile/GVS containment advisory +8/-0

Add changeset for lockfile/GVS containment advisory

• Documents the lockfile depPath name traversal rejection and the global-virtual-store version-segment traversal rejection. Marks patch releases for the affected packages.

.changeset/contain-virtual-store-package-name.md

isolated-linker-name-traversal.mdAdd changeset for manifest-name traversal advisory +7/-0

Add changeset for manifest-name traversal advisory

• Documents rejecting path-traversal scoped manifest names that could write outside node_modules/virtual store. Marks patch releases for resolver/graph-builder and pnpm.

.changeset/isolated-linker-name-traversal.md

Other (8) +41 / -2
package.jsonEnable Jest tests and add symlink-dependency workspace dep +4/-2

Enable Jest tests and add symlink-dependency workspace dep

• Expands lint to include tests and updates the test script to run Jest after compile. Adds @pnpm/symlink-dependency so graph-builder can use safeJoinModulesDir.

deps/graph-builder/package.json

tsconfig.jsonAdd test tsconfig for graph-builder Jest suite +17/-0

Add test tsconfig for graph-builder Jest suite

• Adds a test-specific TypeScript project config to compile test sources and include repo typings. Supports running Jest tests in this package.

deps/graph-builder/test/tsconfig.json

tsconfig.jsonReference symlink-dependency TS project +3/-0

Reference symlink-dependency TS project

• Adds a project reference to fs/symlink-dependency so graph-builder can import safeJoinModulesDir in a TS project-reference build.

deps/graph-builder/tsconfig.json

package.jsonAdd symlink-dependency dependency for safe PnP locations +1/-0

Add symlink-dependency dependency for safe PnP locations

• Adds @pnpm/symlink-dependency to contain packageLocation joins when generating the PnP registry from lockfile data.

lockfile/lockfile-to-pnp/package.json

tsconfig.jsonReference symlink-dependency TS project +3/-0

Reference symlink-dependency TS project

• Adds fs/symlink-dependency as a TS project reference to support importing safeJoinModulesDir.

lockfile/lockfile-to-pnp/tsconfig.json

package.jsonAdd symlink-dependency to resolver package +1/-0

Add symlink-dependency to resolver package

• Adds @pnpm/symlink-dependency so resolver code can safely join resolved package names into virtual-store node_modules paths.

pkg-manager/resolve-dependencies/package.json

tsconfig.jsonReference symlink-dependency TS project +3/-0

Reference symlink-dependency TS project

• Adds fs/symlink-dependency as a TS project reference to support importing safeJoinModulesDir with project references.

pkg-manager/resolve-dependencies/tsconfig.json

pnpm-lock.yamlUpdate workspace lockfile for new internal dependencies +9/-0

Update workspace lockfile for new internal dependencies

• Adds workspace link entries for @pnpm/symlink-dependency in the affected importers. Keeps the monorepo lockfile consistent with the new package dependencies.

pnpm-lock.yaml

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (5) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 18 rules

Grey Divider


Remediation recommended

1. Unsorted imports in lockfileToDepGraph.ts 📘 Rule violation ⚙ Maintainability
Description
The updated import list is not grouped/sorted per the required TypeScript import order, making diffs
noisier and harder to audit. The new @pnpm/symlink-dependency import should be placed within a
correctly ordered external-import block.
Code

deps/graph-builder/src/lockfileToDepGraph.ts[R29-32]

+import { safeJoinModulesDir } from '@pnpm/symlink-dependency'
import * as dp from '@pnpm/dependency-path'
import pathExists from 'path-exists'
import equals from 'ramda/src/equals'
Evidence
The compliance rule requires imports to be grouped (stdlib/external/relative) and external imports
alphabetically sorted. In this file, the external imports (including the newly added
@pnpm/symlink-dependency) are not in alphabetical order.

Rule 713472: Enforce consistent TypeScript import order
deps/graph-builder/src/lockfileToDepGraph.ts[1-35]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
TypeScript imports are not grouped and alphabetically ordered as required.

## Issue Context
This PR adds `safeJoinModulesDir`, touching the import block; the file should follow the repo import-order convention (stdlib, external sorted, then relative; blank lines between groups).

## Fix Focus Areas
- deps/graph-builder/src/lockfileToDepGraph.ts[1-35]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Unsorted imports in lockfile-to-pnp 📘 Rule violation ⚙ Maintainability
Description
The import block is not ordered per the required TypeScript import ordering rules after adding
@pnpm/symlink-dependency. This reduces consistency across the codebase and increases review
overhead.
Code

lockfile/lockfile-to-pnp/src/index.ts[R8-11]

+import { safeJoinModulesDir } from '@pnpm/symlink-dependency'
import { depPathToFilename, refToRelative } from '@pnpm/dependency-path'
import { generateInlinedScript, type PackageRegistry } from '@yarnpkg/pnp'
import normalizePath from 'normalize-path'
Evidence
Rule 713472 requires stdlib imports first and external imports sorted alphabetically. The updated
import list includes the newly added @pnpm/symlink-dependency but the overall external import
ordering is not alphabetical.

Rule 713472: Enforce consistent TypeScript import order
lockfile/lockfile-to-pnp/src/index.ts[1-12]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The import declarations are not grouped/sorted according to the required import order.

## Issue Context
This PR introduces `safeJoinModulesDir` and adds a new import; the import section should be updated to match the standard ordering.

## Fix Focus Areas
- lockfile/lockfile-to-pnp/src/index.ts[1-12]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Unsorted imports in resolve-dependencies 📘 Rule violation ⚙ Maintainability
Description
After adding @pnpm/symlink-dependency, the external imports in this file are not maintained in the
required sorted/grouped order. This violates the project’s TypeScript import-order convention.
Code

pkg-manager/resolve-dependencies/src/index.ts[R16-19]

import { safeReadPackageJsonFromDir } from '@pnpm/read-package-json'
+import { safeJoinModulesDir } from '@pnpm/symlink-dependency'
import {
  type DependenciesField,
Evidence
The rule requires external imports to be alphabetically ordered and separated from stdlib/relative
groups. The import block (including the newly added @pnpm/symlink-dependency) is not in the
required order.

Rule 713472: Enforce consistent TypeScript import order
pkg-manager/resolve-dependencies/src/index.ts[1-35]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Imports are not grouped/sorted per the TypeScript import order rule.

## Issue Context
A new external import (`@pnpm/symlink-dependency`) was added; the import section should be adjusted to keep external imports alphabetically ordered.

## Fix Focus Areas
- pkg-manager/resolve-dependencies/src/index.ts[1-35]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


View more (2)
4. Import groups mixed in resolvePeers.ts 📘 Rule violation ⚙ Maintainability
Description
The updated imports include a newly added external dependency but the file’s import block
interleaves Node.js stdlib with external dependencies instead of grouping them. This breaks the
required import grouping rules.
Code

pkg-manager/resolve-dependencies/src/resolvePeers.ts[R15-18]

import { depPathToFilename, createPeerDepGraphHash, type PeerId } from '@pnpm/dependency-path'
+import { safeJoinModulesDir } from '@pnpm/symlink-dependency'
import partition from 'ramda/src/partition'
import pick from 'ramda/src/pick'
Evidence
Rule 713472 requires Node.js standard library imports to be grouped first, followed by external
dependencies. In this file, path is interleaved with external imports, and the updated block
includes the new @pnpm/symlink-dependency import without bringing the block into compliance.

Rule 713472: Enforce consistent TypeScript import order
pkg-manager/resolve-dependencies/src/resolvePeers.ts[1-20]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Import declarations are not grouped by stdlib/external/relative as required.

## Issue Context
This PR adds `@pnpm/symlink-dependency`; the import list should be reorganized to keep Node.js core imports (like `path`) in the stdlib group and external dependencies sorted.

## Fix Focus Areas
- pkg-manager/resolve-dependencies/src/resolvePeers.ts[1-20]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


5. Unsorted imports in fromTarball.ts 📘 Rule violation ⚙ Maintainability
Description
The newly added @pnpm/test-fixtures import leaves the external imports unsorted and the import
grouping inconsistent. This violates the required TypeScript import-order convention.
Code

pkg-manager/core/test/install/fromTarball.ts[R1-5]

import { prepareEmpty } from '@pnpm/prepare'
import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
+import { fixtures } from '@pnpm/test-fixtures'
import { addDependenciesToPackage } from '@pnpm/core'
import { testDefaults } from '../utils/index.js'
Evidence
Rule 713472 requires external imports to be sorted alphabetically within their group. After adding
@pnpm/test-fixtures, the external @pnpm/* imports are not alphabetically ordered.

Rule 713472: Enforce consistent TypeScript import order
pkg-manager/core/test/install/fromTarball.ts[1-6]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Imports are not ordered according to the standard (stdlib first, then external sorted, then relative).

## Issue Context
This PR adds `@pnpm/test-fixtures`; update the import section to keep external imports alphabetically ordered and grouped consistently.

## Fix Focus Areas
- pkg-manager/core/test/install/fromTarball.ts[1-6]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

6. Per-node split allocation 🐞 Bug ➹ Performance
Description
assertNoPathTraversal() uses version.split(/[/\\]/) for every node in iterateHashedGraphNodes(),
which allocates an array per package during dependency graph hashing. This is a small but avoidable
overhead on the install hot path (graph extension computes a hash for each dep).
Code

packages/calc-dep-state/src/index.ts[R130-136]

+function assertNoPathTraversal (version: string): void {
+  if (version.split(/[/\\]/).includes('..')) {
+    const error = new Error(`Refusing to build a virtual-store path with the traversal version segment ${JSON.stringify(version)}`) as Error & { code: string }
+    error.code = 'ERR_PNPM_INVALID_DEPENDENCY_NAME'
+    throw error
+  }
+}
Evidence
The new guard is implemented with split() inside iterateHashedGraphNodes(), so it runs once per
yielded node. extendGraph() calls iterateHashedGraphNodes() while iterating the whole dependency
graph to compute each node’s hash and modules path, making this per-package overhead on
installs.

packages/calc-dep-state/src/index.ts[91-136]
pkg-manager/resolve-dependencies/src/index.ts[468-489]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`assertNoPathTraversal(version)` currently does `version.split(/[/\\]/).includes('..')`, which allocates an array per call. `iterateHashedGraphNodes()` is invoked across the dependency graph during installs, so this adds repeated allocations on a hot path.

### Issue Context
This check is security-motivated and correct, but it can be implemented without allocations.

### Fix Focus Areas
- packages/calc-dep-state/src/index.ts[91-136]

### Suggested fix
Replace the split+includes with a non-allocating test, e.g.:
- Fast precheck: `if (!version.includes('..')) return`
- Then a delimiter-aware regex test: `/((^|[\\/])\.\.(?=([\\/]|$)))/.test(version)`

Keep the same error code (`ERR_PNPM_INVALID_DEPENDENCY_NAME`).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

Auto-approved notes - no code suggestions found
- 'approve_pr_on_self_review' flag enabled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants