ws: close payload error collapsing to BadOpCode and dispatcher state transition panics
Author: Sruhvx-jpgCreated Sep 27, 2026Updated Sep 27, 2026
Summary
During an AI-assisted systems audit of actix-http/src/ws/, error fidelity collapsing and state transition panic hazards were identified in close payload parsing and dispatcher error extraction.
1. Close Frame Error Collapsing into ProtocolError::BadOpCode
- Location:
actix-http/src/ws/frame.rs:218, 227(try_parse_close_payload) - Current Implementation:
if !matches!(raw_code, 1000..=1003 | 1007..=1014 | 3000..=4999) { // TODO(semver-major): use this instead // return Err(ProtocolError::InvalidCloseCode(raw_code)); return Err(ProtocolError::BadOpCode); } if payload.len() > 2 { str::from_utf8(&payload[2..]).map_err(|_| { // TODO(semver-major): use this instead // ProtocolError::InvalidCloseReason ProtocolError::BadOpCode })?; } - Issues:
- Invalid close status codes (e.g.,
1004,1005,1006,1015) and invalid UTF-8 in the close reason string are collapsed intoProtocolError::BadOpCode. - This conflates frame opcode parsing errors with close payload validation errors, violating error mapping fidelity and impeding diagnosis.
- Invalid close status codes (e.g.,
2. Unchecked panic!() in Dispatcher State Error Handlers
- Location:
actix-http/src/ws/dispatcher.rs:208, 215 - Current Implementation:
fn take_error(&mut self) -> DispatcherError<S::Error, U, I> { match mem::replace(self, State::Processing) { State::Error(err) => err, _ => panic!(), } } fn take_framed_error(&mut self) -> DispatcherError<S::Error, U, I> { match mem::replace(self, State::Processing) { State::FramedError(err) => err, _ => panic!(), } } - Issues:
- Bare
panic!()is used on unexpected state transitions rather than returning an explicit state error or propagating an unrecoverable failure cleanly.
- Bare
Note: This issue was identified via an AI-assisted systems audit suite.
Source: actix/actix-web