Uh oh!
There was an error while loading. Please reload this page.
child_process: harden the API - #30008
Conversation
nodejs-github-bot
commented
Oct 17, 2019
vdeturckheim
left a comment
There was a problem hiding this comment.
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?
watson
commented
Oct 17, 2019
@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 |
vdeturckheim
commented
Oct 17, 2019
@watson nop, I was believing that too. So LGTM! Thanks for the clarification! |
975e975 to
e9b6e3bComparewatson
commented
Oct 17, 2019
Force pushed to fix linting errors... I wonder why my tests locally didn't catch these - I guess |
watson
commented
Oct 17, 2019
@vdeturckheim I just took a second look at the code regarding your original concern, and technically |
nodejs-github-bot
commented
Oct 17, 2019
e9b6e3b to
4432aebComparewatson
commented
Oct 17, 2019
More linting errors 🙄 I found that neither |
nodejs-github-bot
commented
Oct 17, 2019
richardlau
commented
Oct 17, 2019
It does run the linting but any failures are being masked. #30012 should fix that. |
watson
commented
Oct 17, 2019
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 |
richardlau
commented
Oct 17, 2019
https://ci.nodejs.org/job/node-test-binary-windows-2/3579/testReport/ |
4432aeb to
a671e14CompareEnsure 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
2267b31CompareThere 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 |
gireeshpunathil
commented
Oct 18, 2019
@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? |
watson
commented
Oct 18, 2019
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 |
sam-github
commented
Oct 18, 2019
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? |
devsnek
commented
Oct 18, 2019
Should we do a benchmark run for the child_process APIs? I assume this would hit them a bit. |
watson
commented
Oct 21, 2019
Good idea. I'll update the docs 👍
Good point. Once we have the final version of the PR ready we should run the |
BridgeAR
commented
Jan 12, 2020
What's the status here? |
8ae28ff to
2935f72CompareThis 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 theenvoption.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
optionsobject that contains anenvproperty 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_processbenchmarks