-
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: harden against prototype pollution #48726
Merged
nodejs-github-bot
merged 1 commit into
nodejs:main
from
LiviaMedeiros:childprocess-harden-protopollution
Jul 14, 2023
Merged
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 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 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,59 @@ | ||
import * as common from '../common/index.mjs'; | ||
import * as fixtures from '../common/fixtures.mjs'; | ||
import { EOL } from 'node:os'; | ||
import { strictEqual } from 'node:assert'; | ||
import cp from 'node:child_process'; | ||
|
||
// TODO(LiviaMedeiros): test on different platforms | ||
if (!common.isLinux) | ||
common.skip(); | ||
|
||
const expectedCWD = process.cwd(); | ||
const expectedUID = process.getuid(); | ||
|
||
for (const tamperedCwd of ['', '/tmp', '/not/existing/malicious/path', 42n]) { | ||
Object.prototype.cwd = tamperedCwd; | ||
|
||
cp.exec('pwd', common.mustSucceed((out) => { | ||
strictEqual(`${out}`, `${expectedCWD}${EOL}`); | ||
})); | ||
strictEqual(`${cp.execSync('pwd')}`, `${expectedCWD}${EOL}`); | ||
cp.execFile('pwd', common.mustSucceed((out) => { | ||
strictEqual(`${out}`, `${expectedCWD}${EOL}`); | ||
})); | ||
strictEqual(`${cp.execFileSync('pwd')}`, `${expectedCWD}${EOL}`); | ||
cp.spawn('pwd').stdout.on('data', common.mustCall((out) => { | ||
strictEqual(`${out}`, `${expectedCWD}${EOL}`); | ||
})); | ||
strictEqual(`${cp.spawnSync('pwd').stdout}`, `${expectedCWD}${EOL}`); | ||
|
||
delete Object.prototype.cwd; | ||
} | ||
|
||
for (const tamperedUID of [0, 1, 999, 1000, 0n, 'gwak']) { | ||
Object.prototype.uid = tamperedUID; | ||
|
||
cp.exec('id -u', common.mustSucceed((out) => { | ||
strictEqual(`${out}`, `${expectedUID}${EOL}`); | ||
})); | ||
strictEqual(`${cp.execSync('id -u')}`, `${expectedUID}${EOL}`); | ||
cp.execFile('id', ['-u'], common.mustSucceed((out) => { | ||
strictEqual(`${out}`, `${expectedUID}${EOL}`); | ||
})); | ||
strictEqual(`${cp.execFileSync('id', ['-u'])}`, `${expectedUID}${EOL}`); | ||
cp.spawn('id', ['-u']).stdout.on('data', common.mustCall((out) => { | ||
strictEqual(`${out}`, `${expectedUID}${EOL}`); | ||
})); | ||
strictEqual(`${cp.spawnSync('id', ['-u']).stdout}`, `${expectedUID}${EOL}`); | ||
|
||
delete Object.prototype.uid; | ||
} | ||
|
||
{ | ||
Object.prototype.execPath = '/not/existing/malicious/path'; | ||
|
||
// Does not throw ENOENT | ||
cp.fork(fixtures.path('empty.js')); | ||
|
||
delete Object.prototype.execPath; | ||
} |
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.
Not related to this PR, but I wonder if we should use
{ __proto__: options, shell: false }
and let users decide if they want prototype pollution or not.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.
Wouldn't it make this object affected by subsequent mutations outside?
In fact, I wonder if we should use
structuredClone()
or at least make copies of object properties like.env
to avoid race conditions if multiplefork()
s are called with reused options.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 it depends if we read the properties in the same tick or not (which I expect we do most of the time, but I haven't checked).
That wouldn't help with inconsistency of our API: sometimes, we dismiss inherited properties, sometimes we don't. But it's clearly not a big deal as I don't think we ever received any bug report regarding that.
but wouldn't folks expect the same env to be shared if they supply the same object? The fact that no one complains makes me think we're overthinking it 😅