fix(cli): Use explicit shell invocation to prevent command injection (VULN-1080)#1271
fix(cli): Use explicit shell invocation to prevent command injection (VULN-1080)#1271fix-it-felix-sentry[bot] wants to merge 1 commit intomainfrom
Conversation
This change addresses VULN-1080 by replacing the implicit shell=true option with explicit shell invocation using sh/cmd.exe. This provides the same functionality while being more explicit about shell execution and avoiding potential command injection risks. Changes: - Removed shell=true option from spawn() call - Added explicit shell executable (sh on Unix, cmd.exe on Windows) - Used shell flags (-c for Unix, /c for Windows) to execute commands - Maintained backward compatibility with package.json script execution Resolves: https://linear.app/getsentry/issue/VULN-1080 Resolves: https://linear.app/getsentry/issue/BE-623
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛Cli
Other
Internal Changes 🔧Deps
Other
Other
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ Patch coverage is 100.00%. Project has 1348 uncovered lines. Files with missing lines (31)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 76.31% 76.31% —%
==========================================
Files 47 47 —
Lines 5690 5690 —
Branches 611 611 —
==========================================
+ Hits 4342 4342 —
- Misses 1348 1348 —
- Partials 5 5 —Generated by Codecov Action |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| // This provides the same functionality while being more explicit about shell execution | ||
| const shellExecutable = process.platform === "win32" ? "cmd.exe" : "sh"; | ||
| const shellFlag = process.platform === "win32" ? "/c" : "-c"; | ||
| cmdArgs = [shellExecutable, shellFlag, packageJson.scriptCommand]; |
There was a problem hiding this comment.
Windows shell invocation missing /d and /s flags
Medium Severity
On Windows, Node.js shell: true internally invokes cmd.exe /d /s /c "command", but the replacement only uses /c. The missing /d flag means registry AutoRun commands could execute before the user's script (ironically a security regression for a security fix). The missing /s flag changes how cmd.exe handles quote stripping after /c, which can break scripts containing quoted arguments (e.g., node -e "console.log('hi')"). The command also isn't wrapped in double quotes as Node.js does internally.


Summary
This PR addresses a security finding identified by Semgrep regarding potential command injection vulnerability in the
spotlight runCLI command.Changes
shell=trueoption with explicit shell invocationsh -con Unix systems andcmd.exe /con Windowsshellvariable as it's no longer neededTechnical Details
The previous implementation used
spawn()withshell: true, which can be vulnerable to command injection if user input is not properly sanitized. While this was a false positive (the input comes from the user's own package.json), the fix follows security best practices by being explicit about shell invocation.Before:
After:
Testing
The existing E2E tests in
tests/e2e/cli/run.e2e.test.tsshould verify that:References