1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-06-25 06:39:22 +02:00

refactor websocket key hashing (#2035)

This commit is contained in:
Rob Ede
2021-02-28 19:55:34 +00:00
committed by GitHub
parent c836de44af
commit cd652dca75
8 changed files with 234 additions and 76 deletions

View File

@ -18,24 +18,31 @@ pub enum WsClientError {
/// Invalid response status
#[display(fmt = "Invalid response status")]
InvalidResponseStatus(StatusCode),
/// Invalid upgrade header
#[display(fmt = "Invalid upgrade header")]
InvalidUpgradeHeader,
/// Invalid connection header
#[display(fmt = "Invalid connection header")]
InvalidConnectionHeader(HeaderValue),
/// Missing CONNECTION header
#[display(fmt = "Missing CONNECTION header")]
/// Missing Connection header
#[display(fmt = "Missing Connection header")]
MissingConnectionHeader,
/// Missing SEC-WEBSOCKET-ACCEPT header
#[display(fmt = "Missing SEC-WEBSOCKET-ACCEPT header")]
/// Missing Sec-Websocket-Accept header
#[display(fmt = "Missing Sec-Websocket-Accept header")]
MissingWebSocketAcceptHeader,
/// Invalid challenge response
#[display(fmt = "Invalid challenge response")]
InvalidChallengeResponse(String, HeaderValue),
InvalidChallengeResponse([u8; 28], HeaderValue),
/// Protocol error
#[display(fmt = "{}", _0)]
Protocol(WsProtocolError),
/// Send request error
#[display(fmt = "{}", _0)]
SendRequest(SendRequestError),

View File

@ -381,12 +381,14 @@ impl WebsocketsRequest {
if let Some(hdr_key) = head.headers.get(&header::SEC_WEBSOCKET_ACCEPT) {
let encoded = ws::hash_key(key.as_ref());
if hdr_key.as_bytes() != encoded.as_bytes() {
if hdr_key.as_bytes() != &encoded {
log::trace!(
"Invalid challenge response: expected: {} received: {:?}",
encoded,
"Invalid challenge response: expected: {:?} received: {:?}",
&encoded,
key
);
return Err(WsClientError::InvalidChallengeResponse(
encoded,
hdr_key.clone(),