File tree Expand file tree Collapse file tree 4 files changed +23
-2
lines changed Expand file tree Collapse file tree 4 files changed +23
-2
lines changed Original file line number Diff line number Diff line change 44 "deps" : {
55 "moonbitlang/async" : {
66 "path" : " .."
7- }
7+ },
8+ "moonbitlang/x" : " 0.4.37"
89 },
910 "readme" : " README.md" ,
1011 "repository" : " https://github.com/moonbitlang/async" ,
1314 "description" : " Examples for `moonbitlang/async`" ,
1415 "source" : " ." ,
1516 "preferred-target" : " native"
16- }
17+ }
Original file line number Diff line number Diff line change @@ -275,6 +275,12 @@ pub async fn Client::receive(self : Client) -> Message {
275275 None
276276 }
277277 }
278+ // 0-999 not used
279+ // 1000-2999 reserved for protocol
280+ if (close_code is Other (i ) && i < 3000 ) || close_code is Abnormal {
281+ // Invalid close code
282+ close_code = ProtocolError
283+ }
278284 } else {
279285 guard frame .payload is [] else {
280286 // Invalid close payload
Original file line number Diff line number Diff line change @@ -20,11 +20,19 @@ async fn[R : @io.Reader] read_frame(reader : R) -> Frame {
2020 let byte0 = header [0 ]
2121 let byte1 = header [1 ]
2222 let fin = (byte0 .to_int () & 0x80 ) != 0
23+ let rsv1 = (byte0 .to_int () & 0x40 ) != 0
24+ let rsv2 = (byte0 .to_int () & 0x20 ) != 0
25+ let rsv3 = (byte0 .to_int () & 0x10 ) != 0
2326 let opcode_byte = byte0 & b '\x0F '
2427 let opcode = OpCode ::from_byte (opcode_byte )
2528 let masked = (byte1 .to_int () & 0x80 ) != 0
2629 let mut payload_len = (byte1 .to_int () & 0x7F ).to_int64 ()
2730
31+ // No extensions supported, rejecting frames with RSV bits set
32+ if rsv1 || rsv2 || rsv3 {
33+ raise FrameError
34+ }
35+
2836 // Validate payload length according to RFC 6455 Section 5.5
2937 if opcode is (Close | Ping | Pong ) {
3038 if !fin {
Original file line number Diff line number Diff line change @@ -145,6 +145,12 @@ async fn ServerConnection::serve_read(self : ServerConnection) -> Unit {
145145 return
146146 }
147147 }
148+ // 0-999 not used
149+ // 1000-2999 reserved for protocol
150+ if (close_code is Other (i ) && i < 3000 ) || close_code is Abnormal {
151+ // Invalid close code
152+ close_code = ProtocolError
153+ }
148154 } else {
149155 guard frame .payload is [] else {
150156 // Invalid close payload
You can’t perform that action at this time.
0 commit comments