Skip to content

Fix shell injection in local folder packing#503

Open
Dremig wants to merge 1 commit into
cnpm:masterfrom
Dremig:master
Open

Fix shell injection in local folder packing#503
Dremig wants to merge 1 commit into
cnpm:masterfrom
Dremig:master

Conversation

@Dremig
Copy link
Copy Markdown

@Dremig Dremig commented May 15, 2026

This change is Reviewable

Summary by CodeRabbit

  • Bug Fixes

    • Prevented execution of shell metacharacters in install root paths.
  • Tests

    • Added security validation tests to verify shell metacharacters in install paths are not executed.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

📝 Walkthrough

Walkthrough

This PR introduces a shell-safe command execution utility to prevent shell injection vulnerabilities. A new execFile export wraps execa with shell: false, the local package packing flow switches from shell-interpolated npm pack to this safer method, and security tests verify shell metacharacters are not interpreted.

Changes

Shell-safe command execution for npm pack

Layer / File(s) Summary
Shell-safe execFile utility
lib/utils.js
Import style for execa is updated, and a new execFile(file, args, options) export is added that runs commands via execa with shell: false to prevent shell interpretation.
Safe npm pack invocation
lib/download/local.js
The localFolder function replaces the shell-interpolated npm pack command with a direct call to utils.execFile, passing command and arguments separately.
Shell injection prevention tests
test/installLocal.test.js
Test mocks are updated to expect utils.execFile, async file utilities are imported, and a new security test verifies that shell metacharacters in install paths are not executed.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A safer pack is born today,
No shells shall run or code obey,
With execFile standing guard so true,
Shell injection bids adieu!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix shell injection in local folder packing' clearly and specifically summarizes the main security fix in this changeset: replacing shell-based execution with non-shell execution to prevent shell injection vulnerabilities.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

lib/download/local.js

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-eggache".

(The package "eslint-plugin-eggache" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-eggache@latest --save-dev

The plugin "eslint-plugin-eggache" was referenced from the config file in ".eslintrc » eslint-config-egg".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

lib/utils.js

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-eggache".

(The package "eslint-plugin-eggache" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-eggache@latest --save-dev

The plugin "eslint-plugin-eggache" was referenced from the config file in ".eslintrc » eslint-config-egg".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

test/installLocal.test.js

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-eggache".

(The package "eslint-plugin-eggache" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-eggache@latest --save-dev

The plugin "eslint-plugin-eggache" was referenced from the config file in ".eslintrc » eslint-config-egg".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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 and usage tips.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances security by replacing shell-based command execution with a new utils.execFile utility (using execa with shell: false) when packing local folders. It also introduces a security test case to verify that shell metacharacters in file paths do not lead to command injection. Feedback was provided to improve the robustness of the execFile implementation by ensuring the shell option cannot be overridden by caller options and by simplifying the asynchronous return.

Comment thread lib/utils.js
Comment on lines +668 to +673
exports.execFile = async (file, args, options) => {
return await execa(file, args, {
shell: false,
...options,
});
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

To ensure the security fix is robust, shell: false should be enforced by placing it after ...options. This prevents any caller from accidentally re-enabling the shell. Additionally, the await keyword is redundant when returning a promise directly, and providing default values for args and options improves the function's resilience.

Suggested change
exports.execFile = async (file, args, options) => {
return await execa(file, args, {
shell: false,
...options,
});
};
exports.execFile = (file, args = [], options = {}) => {
return execa(file, args, {
...options,
shell: false,
});
};

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/utils.js`:
- Around line 668-673: The execFile helper (exports.execFile) currently spreads
caller options after setting shell: false, allowing callers to override it and
enable a shell; fix by ensuring shell: false cannot be overridden — either
spread options first and then set shell: false (so the literal wins), or
explicitly set shell: false after merging options (e.g., finalOptions = {
...options, shell: false }) before passing to execa; update exports.execFile to
enforce shell: false regardless of provided options.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cc214f92-98ba-43fb-96b3-3b744dcfeb68

📥 Commits

Reviewing files that changed from the base of the PR and between 0b7296d and ee119d6.

📒 Files selected for processing (3)
  • lib/download/local.js
  • lib/utils.js
  • test/installLocal.test.js

Comment thread lib/utils.js
Comment on lines +668 to +673
exports.execFile = async (file, args, options) => {
return await execa(file, args, {
shell: false,
...options,
});
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Critical: Spread operator order allows shell override.

The spread operator ...options comes after shell: false, which means callers can override the security setting by passing { shell: true } in options. This defeats the purpose of execFile as a shell-safe execution helper.

🔒 Proposed fix to prevent override
 exports.execFile = async (file, args, options) => {
   return await execa(file, args, {
-    shell: false,
     ...options,
+    shell: false,
   });
 };

This ensures shell: false always takes precedence, even if a caller mistakenly passes shell: true.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
exports.execFile = async (file, args, options) => {
return await execa(file, args, {
shell: false,
...options,
});
};
exports.execFile = async (file, args, options) => {
return await execa(file, args, {
...options,
shell: false,
});
};
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/utils.js` around lines 668 - 673, The execFile helper (exports.execFile)
currently spreads caller options after setting shell: false, allowing callers to
override it and enable a shell; fix by ensuring shell: false cannot be
overridden — either spread options first and then set shell: false (so the
literal wins), or explicitly set shell: false after merging options (e.g.,
finalOptions = { ...options, shell: false }) before passing to execa; update
exports.execFile to enforce shell: false regardless of provided options.

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.

1 participant