diff options
author | Kenta Moriuchi <moriken@kimamass.com> | 2024-01-04 13:12:38 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-04 09:42:38 +0530 |
commit | b2cd254c35b6b1b128beea0eacdb8e814d91e003 (patch) | |
tree | d55fa5910e32d8a664aff5b680e07debea93181e /ext/websocket/01_websocket.js | |
parent | 48556748577ba46db5f9212d14a0fcaa90d632f6 (diff) |
fix: strict type check for cross realms (#21669)
Deno v1.39 introduces `vm.runInNewContext`. This may cause problems when
using `Object.prototype.isPrototypeOf` to check built-in types.
```js
import vm from "node:vm";
const err = new Error();
const crossErr = vm.runInNewContext(`new Error()`);
console.assert( !(crossErr instanceof Error) );
console.assert( Object.getPrototypeOf(err) !== Object.getPrototypeOf(crossErr) );
```
This PR changes to check using internal slots solves them.
---
current:
```
> import vm from "node:vm";
undefined
> vm.runInNewContext(`new Error("message")`)
Error {}
> vm.runInNewContext(`new Date("2018-12-10T02:26:59.002Z")`)
Date {}
```
this PR:
```
> import vm from "node:vm";
undefined
> vm.runInNewContext(`new Error("message")`)
Error: message
at <anonymous>:1:1
> vm.runInNewContext(`new Date("2018-12-10T02:26:59.002Z")`)
2018-12-10T02:26:59.002Z
```
---------
Co-authored-by: Bartek IwaĆczuk <biwanczuk@gmail.com>
Diffstat (limited to 'ext/websocket/01_websocket.js')
-rw-r--r-- | ext/websocket/01_websocket.js | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/ext/websocket/01_websocket.js b/ext/websocket/01_websocket.js index 57689d1ae..fdcb0be99 100644 --- a/ext/websocket/01_websocket.js +++ b/ext/websocket/01_websocket.js @@ -7,7 +7,7 @@ import { URL } from "ext:deno_url/00_url.js"; import * as webidl from "ext:deno_webidl/00_webidl.js"; import { createFilteredInspectProxy } from "ext:deno_console/01_console.js"; import { HTTP_TOKEN_CODE_POINT_RE } from "ext:deno_web/00_infra.js"; -import DOMException from "ext:deno_web/01_dom_exception.js"; +import { DOMException } from "ext:deno_web/01_dom_exception.js"; import { CloseEvent, defineEventHandler, @@ -21,7 +21,6 @@ import { import { Blob, BlobPrototype } from "ext:deno_web/09_file.js"; import { getLocationHref } from "ext:deno_web/12_location.js"; const { - ArrayBufferPrototype, ArrayBufferIsView, ArrayPrototypeJoin, ArrayPrototypeMap, @@ -29,21 +28,24 @@ const { ErrorPrototypeToString, ObjectDefineProperties, ObjectPrototypeIsPrototypeOf, + PromisePrototypeCatch, PromisePrototypeThen, RegExpPrototypeExec, SafeSet, SetPrototypeGetSize, - // TODO(lucacasonato): add SharedArrayBuffer to primordials - // SharedArrayBufferPrototype String, StringPrototypeEndsWith, StringPrototypeToLowerCase, Symbol, - SymbolIterator, - PromisePrototypeCatch, SymbolFor, + SymbolIterator, TypedArrayPrototypeGetByteLength, + Uint8Array, } = primordials; +const { + isAnyArrayBuffer, + isArrayBuffer, +} = core; import { op_ws_check_permission_and_cancel_handle, op_ws_close, @@ -80,11 +82,7 @@ webidl.converters["WebSocketSend"] = (V, prefix, context, opts) => { return webidl.converters["Blob"](V, prefix, context, opts); } if (typeof V === "object") { - if ( - ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, V) || - // deno-lint-ignore prefer-primordials - ObjectPrototypeIsPrototypeOf(SharedArrayBuffer.prototype, V) - ) { + if (isAnyArrayBuffer(V)) { return webidl.converters["ArrayBuffer"](V, prefix, context, opts); } if (ArrayBufferIsView(V)) { @@ -329,8 +327,7 @@ class WebSocket extends EventTarget { if (ArrayBufferIsView(data)) { op_ws_send_binary(this[_rid], data); - } else if (ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, data)) { - // deno-lint-ignore prefer-primordials + } else if (isArrayBuffer(data)) { op_ws_send_binary(this[_rid], new Uint8Array(data)); } else if (ObjectPrototypeIsPrototypeOf(BlobPrototype, data)) { PromisePrototypeThen( |