-
-
Notifications
You must be signed in to change notification settings - Fork 229
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
Support single string input without using the shell
option
#182
Support single string input without using the shell
option
#182
Conversation
Rebased to latest |
shell
shell
option
Sorry for the slow response. Too many PRs to review. Are you sure there's no possibility of injection attacks using this? That's what's been holding me back from adding this in the past. |
Does this work on |
Maybe we should add a note in |
I have fixed what you mentioned in the code review 👍 Yes this works with There is already a note in the I think for the injection attacks: it can happen with
const userInput = '$SOME_SECRET_VAR';
execa.shell(`echo ${userInput}`);
const userInput = '$( rm -rf / )';
execa.shell(`echo ${userInput}`); With Actually this PR translates I just checked the Node source code and arguments passed to the underlying So overall this will actually improve security by discouraging users from using |
Thanks for the review! This is all fixed now. |
shell
optionshell
option
This is looking great now. Thanks for spending so much time on perfecting it 👌 |
@sindresorhus @ehmicky It would be super nice if you were to publish these changes to npm quickly. I've been using Snyk for checking security vulnerabilities in my projects and the latest Snyk is using [email protected] and [email protected] which still allows More on this https://app.snyk.io/vuln/SNYK-JS-EXECA-174564 |
I think Snyk is getting this wrong. I just sent an email to Snyk mostly copy/pasting this message, and asking if they could remove this vulnerability warning. Zendesk ticket here: https://support.snyk.io/hc/en-us/requests/374?flash_digest=9f426e2665b5434970bca8d3421577124b9f64bd (not sure if this can be viewed by anyone). Note: @sindresorhus has npm publish access. Details: Node.js
What this PR does is to encourage users not to use the const argumentsArray = ['echo', ['rm', '-r', '/some/dir']]
const argumentsString = 'echo rm -r /some/dir'
// Those commands won't execute `rm`
child_process.spawn(...argumentsArray)
execa(...argumentsArray)
// Those commands will execute `rm`
child_process.spawn(argumentsString, { shell: true })
child_process.exec(argumentsString)
execa(argumentsString, { shell: true })
execa.shell(argumentsString)
// Added by this PR. It won't execute `rm`
execa(argumentsString) |
@ehmicky Hey, I'm one of the engineers at Snyk. Thanks for the update. We're pulling it from the vuln db while we re-evaluate. Sorry for the trouble. |
@robcresswell thanks for the quick response! |
@robcresswell This is not ok. Snyk cannot go around publishing false information like this. None of us maintainers were even contacted before the report was published, which would have prevented this mishap. I urge you to improve your processes. |
Snyk vulnerability is now completely removed. See https://support.snyk.io/hc/en-us/requests/374 |
Fix #176
This allows passing command+arguments as a single string with
execa()
without using theshell
option:Instead of:
This is not only for convenience, the main goal is actually to make
execa
more secure, cross-platform and faster. The reason is: many users might be tempted to useexeca.shell()
for the convenience of specifying command and arguments inside a single string, because it feels closer to typing in a terminal. Howeverexeca.shell()
involves using a shell interpreter which is:$(rm -rf /)
or&& rm -rf /
cmd.exe
.Giving users the possibility to do this without
execa.shell()
prevents this issue.Like
execa()
(and the underlyingchild_process.spawn()
) arguments do not need any escaping/quoting. One exception: spaces can be escaped with a backslash if not meant as an arguments delimiter.