fix: support npm 12 pack metadata - #18
Conversation
PR Summary by QodoFix npm pack JSON parsing for npm 12 metadata format
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1. Tarball path unvalidated
|
| ); | ||
| const packEntries = JSON.parse(stdout) as NpmPackEntry[]; | ||
| const metadata = packEntries[0]; | ||
| const packEntries = parseNpmPackOutput(stdout); |
There was a problem hiding this comment.
1. Tarball path unvalidated 🐞 Bug ☼ Reliability
packNpmPackage() now selects the first parsed record with any string filename and builds tarballPath via path.join() without validating that it is a .tgz under destinationPath. That path is then passed into extractTarGz() for gunzip+tar extraction, so unexpected output (e.g., ../something or a non-tarball filename) can cause confusing failures or extraction attempts outside the intended workspace.
Agent Prompt
### Issue description
`packNpmPackage()` accepts any string `metadata.filename` and turns it into `tarballPath` without verifying that it is a tarball path located within `destinationPath`. That path is then immediately gunzipped/extracted.
### Issue Context
`npm pack --json` output is treated as trusted, but this code is parsing external command output. Defensive validation should ensure we only attempt extraction on a real tarball created in the requested destination directory.
### Fix Focus Areas
- src/core/npm-package-doctor.ts[207-242]
### Recommended fix
1. Tighten tarball selection:
- Prefer entries where `filename` is a string and ends with `.tgz`.
2. Resolve and validate the tarball path:
- Compute `const candidatePath = path.isAbsolute(filename) ? filename : path.resolve(destinationPath, filename)`.
- Reject if `!isPathWithinRoot(destinationPath, candidatePath)`.
- Optionally `await stat(candidatePath)` and ensure it’s a file to fail early with a clearer error.
3. Use `candidatePath` as `tarballPath`.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Summary
Verification