From 9b49de46446f3acb3081bfa809652a8a66d54bfb Mon Sep 17 00:00:00 2001 From: Kenta Moriuchi Date: Wed, 26 Apr 2023 07:36:22 +0900 Subject: fix(core): Wrap safe collections' argument of primordials (#18750) --- cli/tests/unit/websocket_test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'cli/tests/unit/websocket_test.ts') diff --git a/cli/tests/unit/websocket_test.ts b/cli/tests/unit/websocket_test.ts index 999eede41..795d5ebc1 100644 --- a/cli/tests/unit/websocket_test.ts +++ b/cli/tests/unit/websocket_test.ts @@ -147,3 +147,25 @@ Deno.test({ }; await Promise.all([promise, server]); }); + +Deno.test( + { sanitizeOps: false }, + function websocketConstructorWithPrototypePollusion() { + const originalSymbolIterator = Array.prototype[Symbol.iterator]; + try { + Array.prototype[Symbol.iterator] = () => { + throw Error("unreachable"); + }; + assertThrows(() => { + new WebSocket( + new URL("ws://localhost:4242/"), + // Allow `Symbol.iterator` to be called in WebIDL conversion to `sequence` + // deno-lint-ignore no-explicit-any + ["soap", "soap"].values() as any, + ); + }, DOMException); + } finally { + Array.prototype[Symbol.iterator] = originalSymbolIterator; + } + }, +); -- cgit v1.2.3