-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
child_process should individually escape args[] on shell: true #29532
Labels
Comments
Artoria2e5
changed the title
child_process.spawn should individually escape args[] on shell: true
child_process should individually escape args[] on shell: true
Sep 12, 2019
Artoria2e5
added a commit
to DimensionDev/Maskbook
that referenced
this issue
Sep 12, 2019
we can node it ourselves; triggered by nodejs/node#29532
bnoordhuis
added
the
child_process
Issues and PRs related to the child_process subsystem.
label
Sep 12, 2019
@Artoria2e5 Do you want to open a PR? It'd be semver-major (i.e., probably won't be released until Node.js v14.x) but it sounds like a reasonable change to me. |
@bnoordhuis Yes, I am working on it. After the test is finished I will open a PR. (They are the referenced commits you see.) |
SunriseFox
pushed a commit
to DimensionDev/Maskbook
that referenced
this issue
Sep 16, 2019
we can node it ourselves; triggered by nodejs/node#29532
Jack-Works
pushed a commit
to DimensionDev/Maskbook
that referenced
this issue
Sep 16, 2019
we can node it ourselves; triggered by nodejs/node#29532
3 tasks
Artoria2e5
added a commit
to Artoria2e5/node
that referenced
this issue
Sep 18, 2019
BREAKING CHANGE: This changes the behavior of args[] in `shell: true` to escape globs and other metacharacters. If you want to keep your scripts, do it the proper way and stuff them in "command." Refs: nodejs#29576 Fixes: nodejs#29532
13 tasks
Artoria2e5
added a commit
to Artoria2e5/node
that referenced
this issue
Jan 11, 2021
BREAKING CHANGE: This changes the behavior of args[] in `shell: true` to escape globs and other metacharacters. If you want to keep your scripts, do it the proper way and stuff them in "command." Refs: nodejs#29576 Fixes: nodejs#29532
The linked PR for this was closed several years ago. I'm closing this issue as 'Stale', but feel-free to revisit. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is probably a design 🐛, and fixing it would require an incompatible change.
The
shell: true
handling ofchild_process
joins the contents ofargs[]
with spaces and simply sends them off to the shell. Although it is documented thatshell: true
is for handling globs and the like, doing so is still inconsiderate and irresponsible because devs expect some degree of safety by putting stuff in an array instead of one long string.The problem? Well,
shell: true
is mandatory for running many of the.cmd
shims on Windows because these things are not otherwise considered executable, so at leastshell: process.platform === 'win32'
is needed. And althoughcmd
does not interpret globs, it does interpret flow control stuff like&
and&&
. Our linter script, set up withlint-staged
, faced exactly that: someone threw in a test script with&
in the filename for it to lint, and the command chopped off at that ampersand because you broke the argument separation. Yes, programming code filenames should not look like that, but neither should a spawning mechanism break!My proposal for the issue is that
nodejs
should escape the contents ofargs
indivudually (map
) before joining them into a/c
or-c
parameter of the shell, and that thecommand
string can instead stay as the wild-west part that people use to put complex shell-only stuff in. In other words, ifcommand
contains nothing special, spawning withshell
set true or false should eventually run the exact same command, the only difference being whether another shell has been started (so things like BASH_ENV will still matter).Implementation matters
Currently the Windows escape is written in C++ as
quote_cmd_arg
. Unix does not require escaping yet as its spawning mechanism already accepts an array of strings. Implementing my suggestion should mean that we should have a version of both in JavaScript:Oh that's right, we need PowerShell too. The whole shell checking will have to move a bit as well as they must be identified before quoting.
The text was updated successfully, but these errors were encountered: