-
Notifications
You must be signed in to change notification settings - Fork 30k
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: harden the API #30008
Conversation
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.
LGTM regarding the code and the behavior - I forsee it can be a braking change for some people. Would doc be enough to mitigate it?
@vdeturckheim Breaking in what way? I was originally thinking it would be breaking if users relied on the prototype chain for some of the properties. But |
@watson nop, I was believing that too. So LGTM! Thanks for the clarification! |
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.
LGTM
975e975
to
e9b6e3b
Compare
Force pushed to fix linting errors... I wonder why my tests locally didn't catch these - I guess |
@vdeturckheim I just took a second look at the code regarding your original concern, and technically |
e9b6e3b
to
4432aeb
Compare
More linting errors 🙄 I found that neither |
It does run the linting but any failures are being masked. #30012 should fix that. |
Looks like the windows tests are filing, but I'm having trouble seeing exactly why. It's not clear to me from the logs, but maybe I'm looking at the wrong logs. E.g. is this the right one? https://ci.nodejs.org/job/node-test-binary-windows-2/3579/console |
https://ci.nodejs.org/job/node-test-binary-windows-2/3579/testReport/ |
4432aeb
to
a671e14
Compare
Ensure that the options object used by exec, execSync, execFile, execFileSync, spawn, spawnSync, and fork, isn't susceptible to prototype pollution. This is achieved by copying all the properties of the options object into another object that doesn't have a prototype.
a671e14
to
2267b31
Compare
There was an oversight in my original patch, which I just fixed and pushed. Unfortunately, that revealed that we actually do "have official support" for inheriting environment variables in the Today the test manipulates the prototype like this: node/test/parallel/test-child-process-env.js Lines 35 to 37 in d769ebc
And expects
If we want to keep support for this (which I guess we have to if we don't want to make this a breaking change), one solution might be to keep the entire prototype chain, except the very last one that points to |
@watson -
can you please elaborate a little more on the attack surface? If an attacker has access to the said objects, can't they very well initiate any arbitrary code in the process? |
Prototype pollution can't by itself be used to do RCE, but given the right set of circumstances in the code base, you might be able to find a way to leverage the polluted prototype to perform RCE. The |
I think this change needs to touch the docs. If I've mixed feelings about this. I think using prototype inheritance on options objects is fairly rare, so I'm OK losing it as a feature. On the other hand... having a node API surface that sometimes allows it and sometimes doesn't seems pretty horrid. Should we do the check everywhere? |
Should we do a benchmark run for the child_process APIs? I assume this would hit them a bit. |
Good idea. I'll update the docs 👍
Good point. Once we have the final version of the PR ready we should run the |
What's the status here? |
8ae28ff
to
2935f72
Compare
This issue/PR was marked as stalled, it will be automatically closed in 30 days. If it should remain open, please leave a comment explaining why it should remain open. |
Closing this because it has stalled. Feel free to reopen if this PR is still relevant, or to ping the collaborator who labelled it stalled if you have any questions. |
Ensure that the options object used by
exec
,execSync
,execFile
,execFileSync
,spawn
,spawnSync
, andfork
, isn't susceptible to prototype pollution.This is achieved by copying all the properties of the options object into another object that doesn't have a prototype.
Background
If an attacker is able to successfully pollute the prototype just before a call to
exec
,execSync
,execFile
,execFileSync
,spawn
,spawnSync
, orfork
, they will be able to perform RCE on most Linux systems by manipulating theenv
option.Recommended alternative
If this PR doesn't land, or if you're running a version of Node.js that doesn't include this change, the recommended way to spawn a child process is:
By actively passing in an
options
object that contains anenv
property you ensure that one isn't created internally which inherits fromObject.prototype
.The above example uses
spawn
, but this approach is also relevant forexec
,execSync
,execFile
,execFileSync
,spawnSync
, andfork
.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passeschild_process
benchmarks