Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! child_process: deprecate passing args to spawn and execFile
  • Loading branch information
aduh95 committed Mar 19, 2025
commit 7a04435f174985bd9b3e7b237923abd3a2dba8e3
4 changes: 3 additions & 1 deletion lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@
}
}

let emittedDEP0190Already = false;
function normalizeSpawnArguments(file, args, options) {
validateString(file, 'file');
validateArgumentNullCheck(file, 'file');
Expand Down Expand Up @@ -611,12 +612,13 @@

if (options.shell) {
validateArgumentNullCheck(options.shell, 'options.shell');
if (args.length > 0) {
if (args.length > 0 && !emittedDEP0190Already) {
process.emitWarning(
'Passing args to a child process with shell option true can lead to security ' +
'vulnerabilities, as the arguments are not escaped, only concatenated.',
'DeprecationWarning',
'DEP0190');
emittedDEP0190Already = true;

Check failure on line 621 in lib/child_process.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Expected indentation of 6 spaces but found 8
}
const command = ArrayPrototypeJoin([file, ...args], ' ');
// Set the shell, switches, and commands.
Expand Down
17 changes: 10 additions & 7 deletions test/parallel/test-child-process-execfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ const fixture = fixtures.path('exit.js');
const echoFixture = fixtures.path('echo.js');
const execOpts = { encoding: 'utf8', shell: true, env: { ...process.env, NODE: process.execPath, FIXTURE: fixture } };

common.expectWarning(
'DeprecationWarning',
'Passing args to a child process with shell option true can lead to security ' +
'vulnerabilities, as the arguments are not escaped, only concatenated.',
'DEP0190');

{
execFile(
process.execPath,
Expand Down Expand Up @@ -47,7 +53,8 @@ const execOpts = { encoding: 'utf8', shell: true, env: { ...process.env, NODE: p
{
// Verify the shell option works properly
execFile(
common.isWindows ? `"${execOpts.env.NODE}" "${execOpts.env.FIXTURE} 0` : `"$NODE" "$FIXTURE" 0`,
`"${common.isWindows ? execOpts.env.NODE : '$NODE'}"`,
[`"${common.isWindows ? execOpts.env.FIXTURE : '$FIXTURE'}"`, 0],
execOpts,
common.mustSucceed(),
);
Expand Down Expand Up @@ -116,14 +123,10 @@ const execOpts = { encoding: 'utf8', shell: true, env: { ...process.env, NODE: p
...(common.isWindows ? [] : [{ encoding: 'utf8' }]),
{ shell: true, encoding: 'utf8' },
].forEach((options) => {
const command = options.shell ?
[[file, ...args].join(' ')] :
[file, args];

const execFileSyncStdout = execFileSync(...command, options);
const execFileSyncStdout = execFileSync(file, args, options);
assert.strictEqual(execFileSyncStdout, `foo bar${os.EOL}`);

execFile(...command, options, common.mustCall((_, stdout) => {
execFile(file, args, options, common.mustCall((_, stdout) => {
assert.strictEqual(stdout, execFileSyncStdout);
}));
});
Expand Down
Loading