Skip to content

Commit deb0917

Browse files
Matthew Garrettevanlucas
Matthew Garrett
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 4a16f9b commit deb0917

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

doc/api/child_process.md

+16
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ added: v0.1.90
149149
Spawns a shell then executes the `command` within that shell, buffering any
150150
generated output.
151151

152+
**Note: Never pass unsanitised user input to this function. Any input
153+
containing shell metacharacters may be used to trigger arbitrary command
154+
execution.**
155+
152156
```js
153157
const exec = require('child_process').exec;
154158
exec('cat *.js bad_file | wc -l', (error, stdout, stderr) => {
@@ -324,6 +328,10 @@ The `child_process.spawn()` method spawns a new process using the given
324328
`command`, with command line arguments in `args`. If omitted, `args` defaults
325329
to an empty array.
326330

331+
**Note: If the `shell` option is enabled, do not pass unsanitised user input to
332+
this function. Any input containing shell metacharacters may be used to
333+
trigger arbitrary command execution.**
334+
327335
A third argument may be used to specify additional options, with these defaults:
328336

329337
```js
@@ -645,6 +653,10 @@ If the process times out, or has a non-zero exit code, this method ***will***
645653
throw. The [`Error`][] object will contain the entire result from
646654
[`child_process.spawnSync()`][]
647655

656+
**Note: Never pass unsanitised user input to this function. Any input
657+
containing shell metacharacters may be used to trigger arbitrary command
658+
execution.**
659+
648660
### child_process.spawnSync(command[, args][, options])
649661
<!-- YAML
650662
added: v0.11.12
@@ -690,6 +702,10 @@ completely exited. Note that if the process intercepts and handles the
690702
`SIGTERM` signal and doesn't exit, the parent process will wait until the child
691703
process has exited.
692704

705+
**Note: If the `shell` option is enabled, do not pass unsanitised user input to
706+
this function. Any input containing shell metacharacters may be used to
707+
trigger arbitrary command execution.**
708+
693709
## Class: ChildProcess
694710
<!-- YAML
695711
added: v2.2.0

0 commit comments

Comments
 (0)