From 87f825b61119bb451203e811a8680e06483236f9 Mon Sep 17 00:00:00 2001 From: Naja Melan Date: Thu, 12 Sep 2019 02:53:51 +0200 Subject: [PATCH] Consider remote sending a frame after sending a close frame a protocol error. The websocket RFC explicitly states this is not allowed. --- src/protocol/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index 9ef16a9c..a8d97b69 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -334,6 +334,11 @@ impl WebSocketContext { Stream: Read + Write, { if let Some(mut frame) = self.frame.read_frame(stream, self.config.max_frame_size)? { + + if !self.state.can_read() { + return Err(Error::Protocol("Remote sent frame after having sent a Close Frame".into())); + } + // MUST be 0 unless an extension is negotiated that defines meanings // for non-zero values. If a nonzero value is received and none of // the negotiated extensions defines the meaning of such a nonzero @@ -398,11 +403,6 @@ impl WebSocketContext { } } - OpCode::Data(_) if !self.state.can_read() => { - // No data processing while closing. - Ok(None) - } - OpCode::Data(data) => { let fin = frame.header().is_final; match data {