-
Notifications
You must be signed in to change notification settings - Fork 11
feat(cli): add show command to preview package contents #247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add prpm show command that allows users and agents to inspect package contents before installing. Supports: - File listing with sizes - --full flag for complete file contents - --file <name> for viewing specific files - --json for programmatic/agent use
|
CodeAnt AI is reviewing your PR. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
🤖 My Senior Dev — Analysis Complete👤 For @khaliqgant📁 Expert in View your contributor analytics → 📊 3 files reviewed • 2 high risk • 4 need attention 🚨 High Risk:
🚀 Open Interactive Review →The full interface unlocks features not available in GitHub:
💬 Chat here: 📖 View all 12 personas & slash commandsYou can interact with me by mentioning In PR comments or on any line of code:
Slash commands:
AI Personas (mention to get their perspective):
For the best experience, view this PR on myseniordev.com — includes AI chat, file annotations, and interactive reviews. |
Nitpicks 🔍
|
| const extract = tar.extract({ | ||
| cwd: tmpDir, | ||
| strict: true, | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: The tarball extraction in the show command does not apply any path-safety or symlink filtering, so a malicious package can include symlinks and crafted paths that cause files to be written outside the temporary directory during extraction, enabling potential file overwrite attacks; you should mirror the hardened extraction used in the install command by blocking symlinks and unsafe paths relative to the temp directory. [security]
Severity Level: Critical 🚨
| }); | |
| // Security: block symlinks and unsafe paths to prevent path traversal attacks | |
| filter: (entryPath: string, entry: any) => { | |
| // Block explicit symlink and hard link entry types | |
| const entryType = 'type' in entry ? entry.type : null; | |
| if (entryType === 'SymbolicLink' || entryType === 'Link') { | |
| console.warn(` ⚠️ Blocked symlink in package: ${entryPath}`); | |
| return false; | |
| } | |
| // Also block filesystem symlinks if exposed via isSymbolicLink() | |
| if ('isSymbolicLink' in entry && typeof (entry as any).isSymbolicLink === 'function' && (entry as any).isSymbolicLink()) { | |
| console.warn(` ⚠️ Blocked symlink in package: ${entryPath}`); | |
| return false; | |
| } | |
| // Basic unsafe path patterns (.., absolute paths, Windows drive letters, null bytes) | |
| if ( | |
| entryPath.includes('..') || | |
| entryPath.startsWith('/') || | |
| /^[a-zA-Z]:/.test(entryPath) || | |
| entryPath.includes('\0') | |
| ) { | |
| console.warn(` ⚠️ Blocked unsafe path in package: ${entryPath}`); | |
| return false; | |
| } | |
| // Ensure the resolved path stays within the temporary directory | |
| const resolvedPath = path.resolve(tmpDir, entryPath); | |
| const resolvedTarget = path.resolve(tmpDir); | |
| if (!resolvedPath.startsWith(resolvedTarget + path.sep) && resolvedPath !== resolvedTarget) { | |
| console.warn(` ⚠️ Blocked path traversal attempt: ${entryPath}`); | |
| return false; | |
| } | |
| return true; | |
| }, |
Why it matters? ⭐
This is a real security issue. The current code calls tar.extract with cwd set to a temp dir but applies no filtering or symlink handling — malicious tarballs can contain symlinks or crafted paths (../, absolute paths, Windows drive paths) that result in files being written outside the temp directory or symlinks pointing elsewhere, enabling file overwrite or information disclosure. The proposed filter mirrors common hardening strategies (block symlinks/links, block absolute/.. paths, and ensure resolved paths remain inside tmpDir) and therefore fixes a real vulnerability rather than being cosmetic.
The suggested implementation is sensible for the tar package API surface (filter/onentry patterns) and matches the threat described. It may need minor tweaks to match exact tar package types, but the core idea (reject symlinks and path traversal) is correct and necessary.
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** packages/cli/src/commands/show.ts
**Line:** 57:57
**Comment:**
*Security: The tarball extraction in the show command does not apply any path-safety or symlink filtering, so a malicious package can include symlinks and crafted paths that cause files to be written outside the temporary directory during extraction, enabling potential file overwrite attacks; you should mirror the hardened extraction used in the install command by blocking symlinks and unsafe paths relative to the temp directory.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.|
CodeAnt AI finished reviewing your PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 issues found across 2 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="packages/cli/src/commands/show.ts">
<violation number="1" location="packages/cli/src/commands/show.ts:54">
P1: Missing security filter for tarball extraction. The `install.ts` command includes a `filter` option that blocks symlinks and path traversal attacks, but this `show` command extracts without these protections. A malicious package could exploit this to write files outside the temp directory.</violation>
<violation number="2" location="packages/cli/src/commands/show.ts:83">
P2: Reading all files as UTF-8 will fail or corrupt binary files. Consider detecting binary files (e.g., by extension or checking for null bytes) and either skipping their content or displaying a placeholder like `[binary file]`.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
- Add security filters for tar extraction (symlinks, path traversal) - Add binary file detection to prevent UTF-8 decode errors - Display binary files with [binary] label and lock icon - Include isBinary field in JSON output
Tests cover: - Basic show functionality (package info, file listing) - Version specification (@pkg@1.0.0) - --full flag (complete file contents) - --file flag (specific file viewing) - --json flag (structured output for agents) - Binary file detection and labeling - Security filters (path traversal protection) - Error handling (not found, download failure) - Package spec parsing (scoped/unscoped, with/without version) - Multi-file packages
User description
Add prpm show command that allows users and agents to inspect
package contents before installing. Supports:
CodeAnt-AI Description
Add 'prpm show' command to preview package contents before installing
What Changed
Impact
✅ Preview package files before install✅ Easier inspection of specific files from packages✅ JSON output for automation and agent workflows💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.