-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
child_process: validate options.shell and correctly enforce shell invocation in exec/execSync #56761
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
Closed
Closed
child_process: validate options.shell and correctly enforce shell invocation in exec/execSync #56761
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { exec, execSync } = require('child_process'); | ||
|
||
const invalidArgTypeError = { | ||
code: 'ERR_INVALID_ARG_TYPE', | ||
name: 'TypeError' | ||
}; | ||
|
||
exec('echo should-be-passed-as-argument', { shell: '' }, common.mustSucceed((stdout, stderr) => { | ||
assert.match(stdout, /should-be-passed-as-argument/); | ||
assert.ok(!stderr); | ||
})); | ||
|
||
{ | ||
const ret = execSync('echo should-be-passed-as-argument', { encoding: 'utf-8', shell: '' }); | ||
assert.match(ret, /should-be-passed-as-argument/); | ||
} | ||
|
||
for (const fn of [exec, execSync]) { | ||
assert.throws(() => fn('should-throw-on-boolean-shell-option', { shell: false }), invalidArgTypeError); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why would we want to accept the empty string a valid value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This suggested change would maintain the existing edge case behaviour when
{ shell: '' }
is passed to exec.spawn()
downstream, because it is not a truthy value, a shell is not invoked.exec()
must always invoke a shell, and therefore anything that passes this validation needs to be a truthy value.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would make more sense to throw on empty string IMO
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd agree, but this would then diverge from the behaviour of the other spawning child_process functions, unless we change them all? (Everywhere else considers
{ shell: '' }
equivalent to{ shell: undefined }
.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could start by deprecating that, sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, two separate PRs eve, one for doc-only deprecation, and one that adds a runtime warning. Would you like to take up that effort?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While deprecated, should the behaviour of
exec(..., { shell: '' })
beexecFile(..., { shell: false })
), orexec(..., { shell: undefined })
?My vote would be for the latter – the whole point of exec is that it always invokes a shell, so I can't see that anyone would be relying on 1 as intended behaviour.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO it should be the current behavior until we move forward with the deprecation at which point it will throw. I don't see the point of introducing an intermediary breaking change only to land another breaking change