Skip to content

Commit

Permalink
Consider remote sending a frame after sending a close frame a protoco…
Browse files Browse the repository at this point in the history
…l error.

The websocket RFC explicitly states this is not allowed.
  • Loading branch information
najamelan committed Sep 19, 2019
1 parent 2d94ea3 commit 0a667e6
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ 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
Expand Down Expand Up @@ -388,9 +391,6 @@ impl WebSocketContext {
OpCtl::Reserved(i) => Err(Error::Protocol(
format!("Unknown control frame type {}", i).into(),
)),
OpCtl::Ping | OpCtl::Pong if !self.state.can_read() => {
Ok(None)
}
OpCtl::Ping => {
let data = frame.into_data();
// No ping processing after we sent a close frame.
Expand All @@ -403,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 {
Expand Down

0 comments on commit 0a667e6

Please sign in to comment.