Skip to content

Commit c7378c4

Browse files
Matthew GarrettMylesBorins
authored andcommitted
doc: warn about unvalidated input in child_process
child_process.exec*() and child_process.spawn*() (if options.shell is true) allow trivial arbitrary command execution if code passes unsanitised user input to it. Add warnings in the docs to make that clear. PR-URL: #10466 Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Sam Roberts <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 52edebc commit c7378c4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

doc/api/child_process.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ added: v0.1.90
141141
Spawns a shell then executes the `command` within that shell, buffering any
142142
generated output.
143143

144+
**Note: Never pass unsanitised user input to this function. Any input
145+
containing shell metacharacters may be used to trigger arbitrary command
146+
execution.**
147+
144148
```js
145149
const exec = require('child_process').exec;
146150
exec('cat *.js bad_file | wc -l', (error, stdout, stderr) => {
@@ -314,6 +318,10 @@ The `child_process.spawn()` method spawns a new process using the given
314318
`command`, with command line arguments in `args`. If omitted, `args` defaults
315319
to an empty array.
316320

321+
**Note: If the `shell` option is enabled, do not pass unsanitised user input to
322+
this function. Any input containing shell metacharacters may be used to
323+
trigger arbitrary command execution.**
324+
317325
A third argument may be used to specify additional options, with these defaults:
318326

319327
```js
@@ -620,6 +628,10 @@ If the process times out, or has a non-zero exit code, this method ***will***
620628
throw. The [`Error`][] object will contain the entire result from
621629
[`child_process.spawnSync()`][]
622630

631+
**Note: Never pass unsanitised user input to this function. Any input
632+
containing shell metacharacters may be used to trigger arbitrary command
633+
execution.**
634+
623635
### child_process.spawnSync(command[, args][, options])
624636
<!-- YAML
625637
added: v0.11.12
@@ -661,6 +673,10 @@ completely exited. Note that if the process intercepts and handles the
661673
`SIGTERM` signal and doesn't exit, the parent process will wait until the child
662674
process has exited.
663675

676+
**Note: If the `shell` option is enabled, do not pass unsanitised user input to
677+
this function. Any input containing shell metacharacters may be used to
678+
trigger arbitrary command execution.**
679+
664680
## Class: ChildProcess
665681
<!-- YAML
666682
added: v2.2.0

0 commit comments

Comments
 (0)