diff --git a/ws/mod.ts b/ws/mod.ts index df8cab01f8ec..9ad76299c390 100644 --- a/ws/mod.ts +++ b/ws/mod.ts @@ -188,11 +188,7 @@ export async function readFrame(buf: BufReader): Promise { // Create client-to-server mask, random 32bit number function createMask(): Uint8Array { - // TODO: use secure and immutable random function. Crypto.getRandomValues() - const arr = Array.from({ length: 4 }).map( - (): number => Math.round(Math.random() * 0xff) - ); - return new Uint8Array(arr); + return crypto.getRandomValues(new Uint8Array(4)); } class WebSocketImpl implements WebSocket {