⚡ Sangsakala Proxy 🏠 Home
Skip to content

JS: Report command injection through child_process argument arrays when shell is enabled - #22978

Open
vishalshetagar wants to merge 2 commits into
github:mainfrom
vishalshetagar:fix/js-shell-command-argument-injection
Open

vishalshetagar wants to merge 2 commits into
github:mainfrom
vishalshetagar:fix/js-shell-command-argument-injection

Conversation

@vishalshetagar

Copy link
Copy Markdown

Description of the fix

js/command-line-injection now reports remote input that reaches the argument array of spawn/execFile when the shell option is set to true or a nonempty string, including their synchronous variants.

const cp = require("child_process");
const app = require("express")();

app.get("/a", (req, res) => {
  cp.exec("echo hello " + req.query.name); // reported
  res.send("ok");
});

app.get("/b", (req, res) => {
  cp.spawn("echo", ["hello", req.query.name], { shell: true }); // now reported
  res.send("ok");
});

app.get("/c", (req, res) => {
  cp.spawn("echo", ["hello", req.query.name], { shell: "/bin/sh" }); // now reported
  res.send("ok");
});

All three routes are now reported by js/command-line-injection. Argument arrays in these examples with shell: false, shell: "", or no shell option remain unreported.

For child_process.spawn, spawnSync, execFile, and execFileSync, the command-injection sink modeling now reuses UnsafeShellCommandConstruction::ShellTrueCommandExecutionSink for shell-interpreted argument arrays. executesArrayAsShell also recognizes nonempty string-valued shell paths, so js/shell-command-constructed-from-input handles those calls as well. The child_process model recognizes the options argument in execFile calls with or without a callback.

Testing

Regression checks cover boolean and string-valued shell options, synchronous variants, callbacks, promisified calls, and argument arrays built with push and unshift. Negative cases cover disabled or omitted shell options and constant arguments.

All 66 targeted checks and the existing CommandInjection and UnsafeShellCommandConstruction query test suites pass.

Fixes #22825.

Copilot AI auto review requested due to automatic review settings November 2, 2026 13:23
@vishalshetagar
vishalshetagar requested a review from a team as a code owner November 2, 2026 13:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JS: js/command-line-injection misses child_process argument arrays when the shell option is set

2 participants