Skip to content

Commit 40f51d8

Browse files
aduh95targos
authored andcommitted
test_runner: protect internals against prototype tampering
PR-URL: #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 0f6d194 commit 40f51d8

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

lib/internal/test_runner/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class Test extends AsyncResource {
222222
}
223223
}
224224

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

227227
if (parent.waitingOn === 0) {
228228
parent.waitingOn = test.testNumber;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
Object.prototype.skip = true;

test/parallel/test-runner-cli.js

+16
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ const testFixtures = fixtures.path('test-runner');
3434
assert.match(stdout, /ok 4 - .+random\.cjs/);
3535
}
3636

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

0 commit comments

Comments
 (0)