-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
process: make source map getter resistant against prototype tampering
Since this code runs during process and Worker shutdown, it should not call user-provided code and thereby e.g. provide a way to break out of `worker.terminate()`. PR-URL: #30228 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ben Coe <bencoe@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
2e729f2
commit 56b3edc
Showing
2 changed files
with
91 additions
and
12 deletions.
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,40 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const tmpdir = require('../common/tmpdir'); | ||
const assert = require('assert'); | ||
|
||
// Attempts to test that the source map JS code run on process shutdown | ||
// does not call any user-defined JS code. | ||
|
||
const { Worker, workerData, parentPort } = require('worker_threads'); | ||
|
||
if (!workerData) { | ||
tmpdir.refresh(); | ||
process.env.NODE_V8_COVERAGE = tmpdir.path; | ||
|
||
// Count the number of some calls that should not be made. | ||
const callCount = new Int32Array(new SharedArrayBuffer(4)); | ||
const w = new Worker(__filename, { workerData: { callCount } }); | ||
w.on('message', common.mustCall(() => w.terminate())); | ||
w.on('exit', common.mustCall(() => { | ||
assert.strictEqual(callCount[0], 0); | ||
})); | ||
return; | ||
} | ||
|
||
const { callCount } = workerData; | ||
|
||
function increaseCallCount() { callCount[0]++; } | ||
|
||
// Increase the call count when a forbidden method is called. | ||
Object.getPrototypeOf((new Map()).entries()).next = increaseCallCount; | ||
Map.prototype.entries = increaseCallCount; | ||
Object.keys = increaseCallCount; | ||
Object.create = increaseCallCount; | ||
Object.hasOwnProperty = increaseCallCount; | ||
Object.defineProperty(Object.prototype, 'value', { | ||
get: increaseCallCount, | ||
set: increaseCallCount | ||
}); | ||
|
||
parentPort.postMessage('done'); |