Skip to content

Commit 88d5c8f

Browse files
committed
chore: protect internals against prototype tampering
PR-URL: nodejs/node#43578 Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 826048c commit 88d5c8f

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

lib/internal/test_runner/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class Test extends AsyncResource {
227227
}
228228
}
229229

230-
const test = new Factory({ fn, name, parent, ...options, ...overrides })
230+
const test = new Factory({ __proto__: null, fn, name, parent, ...options, ...overrides })
231231

232232
if (parent.waitingOn === 0) {
233233
parent.waitingOn = test.testNumber
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict'
2+
3+
Object.prototype.skip = true // eslint-disable-line no-extend-native

test/parallel/test-runner-cli.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ const testFixtures = fixtures.path('test-runner')
3535
assert.match(stdout, /ok 4 - .+random\.cjs/)
3636
}
3737

38+
{
39+
// Same but with a prototype mutation in require scripts.
40+
const args = ['--require', join(testFixtures, 'protoMutation.js'), '--test', testFixtures]
41+
const child = spawnSync(process.execPath, args)
42+
43+
const stdout = child.stdout.toString()
44+
assert.match(stdout, /ok 1 - .+index\.test\.js/)
45+
assert.match(stdout, /not ok 2 - .+random\.test\.mjs/)
46+
assert.match(stdout, /not ok 1 - this should fail/)
47+
assert.match(stdout, /ok 3 - .+subdir.+subdir_test\.js/)
48+
assert.match(stdout, /ok 4 - .+random\.cjs/)
49+
assert.strictEqual(child.status, 1)
50+
assert.strictEqual(child.signal, null)
51+
assert.strictEqual(child.stderr.toString(), '')
52+
}
53+
3854
{
3955
// User specified files that don't match the pattern are still run.
4056
const args = ['--test', testFixtures, join(testFixtures, 'index.js')]

0 commit comments

Comments
 (0)