Skip to content

Commit 823e3f8

Browse files
committed
test_runner: protect internals against prototype tampering
1 parent 3b0995e commit 823e3f8

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
@@ -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;
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;

test/parallel/test-runner-cli.js

Lines changed: 16 additions & 0 deletions
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)