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
Diff Delta:
39
About 16 Diff Delta/hour
Classified as:  General

rootvector2's Description of Work

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.

2 total changed files
Loading changes...
You’ve completed the full review pass
LGTM-land is officially in view