fix(stage): validate staged manifest before writing the tarball #10121

Open
rootvector2 opened 12:55am on October 14, 2026 wants to merge 39 Ξ” into npm/cli latest from
validate-staged-manifest

Pull Request Overview

  • Opened on October 14, 2026
  • Status Open
  • Commit count 1 with first commit October 14, 2026

Total Delta

39 Total Diff Delta

Open Days

Open 17 weekdays

Test Delta

19 Diff Delta in Test Files
Breakdown by Phase

How long has this pull request spent in each phase of its lifecycle?

Data pending calculation for pull request

Author avatar

fix(stage): validate staged manifest before writing the tarball

npm stage download names the output file from the name and version in the staged tarball's own package.json, replacing only the first / in the name and not sanitizing the version at all. A staged manifest with a name like @a/b/../../../../x (or a version containing slashes) keeps its ../ segments, so path.resolve(process.cwd(), filename) escapes the working directory and writeFile drops the attacker-controlled tarball bytes at any writable path. Whoever staged the package controls that manifest, and inspecting an unreviewed stage is the point of this command, so the name and version are now validated right after they are read from the tarball; legitimate stages always pass because the registry enforces the same rules at publish time.

The added tests fail on the previous code: the download succeeded and the tarball landed four directories above the test cwd.

This fix was found and prepared with AI assistance and reviewed by me before submitting.

No comments have been left on this PR.