From b844a09fa561726c7feef2a85688716c0fc1c7cb Mon Sep 17 00:00:00 2001 From: Debadree Chatterjee Date: Fri, 3 Feb 2023 00:37:59 +0530 Subject: [PATCH] stream: dont access Object.prototype.type during TransformStream init Fixes: https://github.com/nodejs/node/issues/46355 PR-URL: https://github.com/nodejs/node/pull/46389 Reviewed-By: Luigi Pinca Reviewed-By: Antoine du Hamel --- lib/internal/webstreams/transformstream.js | 2 ++ test/parallel/test-whatwg-transformstream.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/internal/webstreams/transformstream.js b/lib/internal/webstreams/transformstream.js index 6e119bde63bb2f..411099552941b0 100644 --- a/lib/internal/webstreams/transformstream.js +++ b/lib/internal/webstreams/transformstream.js @@ -358,6 +358,7 @@ function initializeTransformStream( readableSizeAlgorithm) { const writable = new WritableStream({ + __proto__: null, start() { return startPromise.promise; }, write(chunk) { return transformStreamDefaultSinkWriteAlgorithm(stream, chunk); @@ -374,6 +375,7 @@ function initializeTransformStream( }); const readable = new ReadableStream({ + __proto__: null, start() { return startPromise.promise; }, pull() { return transformStreamDefaultSourcePullAlgorithm(stream); diff --git a/test/parallel/test-whatwg-transformstream.js b/test/parallel/test-whatwg-transformstream.js index 0cbc76cc4ce8c0..3276b4dd54a4ec 100644 --- a/test/parallel/test-whatwg-transformstream.js +++ b/test/parallel/test-whatwg-transformstream.js @@ -186,3 +186,22 @@ class Source { inspect(controller, { depth: 0 }), /TransformStreamDefaultController \[/); } + +{ + Object.defineProperty(Object.prototype, 'type', { + get: common.mustNotCall('get %Object.prototype%.type'), + set: common.mustNotCall('set %Object.prototype%.type'), + configurable: true, + }); + + new TransformStream({ + transform(chunk, controller) { + controller.enqueue(chunk); + }, + flush(controller) { + controller.terminate(); + } + }); + + delete Object.prototype.type; +}