diff --git a/lib/web/websocket/receiver.js b/lib/web/websocket/receiver.js index 29b3a32d87d..d1af7b46349 100644 --- a/lib/web/websocket/receiver.js +++ b/lib/web/websocket/receiver.js @@ -314,6 +314,10 @@ class ByteParser extends Writable { code = data.readUInt16BE(0) } + if (code !== undefined && !isValidStatusCode(code)) { + return { code: 1002, reason: 'Invalid status code', error: true } + } + // https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.6 /** @type {Buffer} */ let reason = data.subarray(2) @@ -323,10 +327,6 @@ class ByteParser extends Writable { reason = reason.subarray(3) } - if (code !== undefined && !isValidStatusCode(code)) { - return { code: 1002, reason: 'Invalid status code', error: true } - } - try { reason = utf8Decode(reason) } catch {