From 64af13ee1b430fa7c9a9fa9c711c83e61f6f845e Mon Sep 17 00:00:00 2001 From: Sam Praneis Date: Tue, 6 May 2025 13:51:39 -0500 Subject: [PATCH 1/5] fix(http2): add decriptive error for non-zero connect request address issue #3858: add error type for http/2 connect requests with non-zero body. --- src/error.rs | 16 ++++++++++++++++ src/proto/h2/client.rs | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/error.rs b/src/error.rs index 48917db970..263793ad9d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -131,6 +131,12 @@ pub(super) enum User { feature = "ffi" ))] BodyWriteAborted, + /// User tried to send a connect request with a nonzero body + #[cfg(all( + any(feature = "client", feature = "server"), + feature = "http2" + ))] + InvalidConnectWithBody, /// Error from future of user's Service. #[cfg(any( all(any(feature = "client", feature = "server"), feature = "http1"), @@ -395,6 +401,11 @@ impl Error { Error::new_user(User::Body).with(cause) } + #[cfg(all( any(feature = "client", feature = "server"), feature = "http2"))] + pub(super) fn new_user_invalid_connect() -> Error { + Error::new_user(User::InvalidConnectWithBody) + } + #[cfg(all(any(feature = "client", feature = "server"), feature = "http1"))] pub(super) fn new_shutdown(cause: std::io::Error) -> Error { Error::new(Kind::Shutdown).with(cause) @@ -496,6 +507,11 @@ impl Error { all(any(feature = "client", feature = "server"), feature = "http1"), all(feature = "server", feature = "http2") ))] + #[cfg(all( + any(feature = "client", feature = "server"), + feature = "http2" + ))] + Kind::User(User::InvalidConnectWithBody) => " user sent connect request with non-zero body via HTTP/2", Kind::User(User::Service) => "error from user's Service", #[cfg(any(feature = "http1", feature = "http2"))] #[cfg(feature = "server")] diff --git a/src/proto/h2/client.rs b/src/proto/h2/client.rs index 5e9641e408..3cd743597b 100644 --- a/src/proto/h2/client.rs +++ b/src/proto/h2/client.rs @@ -673,10 +673,10 @@ where && headers::content_length_parse_all(req.headers()) .map_or(false, |len| len != 0) { - warn!("h2 connect request with non-zero body not supported"); + debug!("h2 connect request with non-zero body not supported"); cb.send(Err(TrySendError { - error: crate::Error::new_h2(h2::Reason::INTERNAL_ERROR.into()), - message: None, + error: crate::Error::new_user_invalid_connect(), + message: None })); continue; } From fd226f7174ab74488cb5473140e259e9a9979765 Mon Sep 17 00:00:00 2001 From: Sam Praneis <143520128+samp5@users.noreply.github.com> Date: Tue, 6 May 2025 14:21:16 -0500 Subject: [PATCH 2/5] adj src/error.rs Co-authored-by: Sean McArthur --- src/error.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/error.rs b/src/error.rs index 263793ad9d..6ea7e3a2a1 100644 --- a/src/error.rs +++ b/src/error.rs @@ -511,7 +511,7 @@ impl Error { any(feature = "client", feature = "server"), feature = "http2" ))] - Kind::User(User::InvalidConnectWithBody) => " user sent connect request with non-zero body via HTTP/2", + Kind::User(User::InvalidConnectWithBody) => "user sent CONNECT request with non-zero body", Kind::User(User::Service) => "error from user's Service", #[cfg(any(feature = "http1", feature = "http2"))] #[cfg(feature = "server")] From a72cc2b2c253f563a400aa88535b8b0fff731981 Mon Sep 17 00:00:00 2001 From: Sam Praneis Date: Tue, 6 May 2025 15:11:40 -0500 Subject: [PATCH 3/5] format --- src/error.rs | 16 ++++++---------- src/proto/h2/client.rs | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/error.rs b/src/error.rs index 6ea7e3a2a1..d36b33b06b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -132,10 +132,7 @@ pub(super) enum User { ))] BodyWriteAborted, /// User tried to send a connect request with a nonzero body - #[cfg(all( - any(feature = "client", feature = "server"), - feature = "http2" - ))] + #[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))] InvalidConnectWithBody, /// Error from future of user's Service. #[cfg(any( @@ -401,7 +398,7 @@ impl Error { Error::new_user(User::Body).with(cause) } - #[cfg(all( any(feature = "client", feature = "server"), feature = "http2"))] + #[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))] pub(super) fn new_user_invalid_connect() -> Error { Error::new_user(User::InvalidConnectWithBody) } @@ -507,11 +504,10 @@ impl Error { all(any(feature = "client", feature = "server"), feature = "http1"), all(feature = "server", feature = "http2") ))] - #[cfg(all( - any(feature = "client", feature = "server"), - feature = "http2" - ))] - Kind::User(User::InvalidConnectWithBody) => "user sent CONNECT request with non-zero body", + #[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))] + Kind::User(User::InvalidConnectWithBody) => { + "user sent CONNECT request with non-zero body" + } Kind::User(User::Service) => "error from user's Service", #[cfg(any(feature = "http1", feature = "http2"))] #[cfg(feature = "server")] diff --git a/src/proto/h2/client.rs b/src/proto/h2/client.rs index 3cd743597b..faf36dde7f 100644 --- a/src/proto/h2/client.rs +++ b/src/proto/h2/client.rs @@ -676,7 +676,7 @@ where debug!("h2 connect request with non-zero body not supported"); cb.send(Err(TrySendError { error: crate::Error::new_user_invalid_connect(), - message: None + message: None, })); continue; } From 99653c1cb87c5451193d8ccbd6bbe13c5d98dae1 Mon Sep 17 00:00:00 2001 From: Sam Praneis Date: Tue, 6 May 2025 15:25:53 -0500 Subject: [PATCH 4/5] small fixup for `User::Service` not found --- src/error.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/error.rs b/src/error.rs index d36b33b06b..0c2bb58aa8 100644 --- a/src/error.rs +++ b/src/error.rs @@ -500,14 +500,14 @@ impl Error { feature = "ffi" ))] Kind::User(User::BodyWriteAborted) => "user body write aborted", - #[cfg(any( - all(any(feature = "client", feature = "server"), feature = "http1"), - all(feature = "server", feature = "http2") - ))] #[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))] Kind::User(User::InvalidConnectWithBody) => { "user sent CONNECT request with non-zero body" } + #[cfg(any( + all(any(feature = "client", feature = "server"), feature = "http1"), + all(feature = "server", feature = "http2") + ))] Kind::User(User::Service) => "error from user's Service", #[cfg(any(feature = "http1", feature = "http2"))] #[cfg(feature = "server")] From e2f0bfd65ad3f9c5acfa984af6a7c4147600e0a5 Mon Sep 17 00:00:00 2001 From: Sam Praneis Date: Tue, 6 May 2025 15:52:41 -0500 Subject: [PATCH 5/5] fix incorrect conditional compilation --- src/error.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/error.rs b/src/error.rs index 0c2bb58aa8..2bbb166811 100644 --- a/src/error.rs +++ b/src/error.rs @@ -132,7 +132,7 @@ pub(super) enum User { ))] BodyWriteAborted, /// User tried to send a connect request with a nonzero body - #[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))] + #[cfg(all(feature = "client", feature = "http2"))] InvalidConnectWithBody, /// Error from future of user's Service. #[cfg(any( @@ -398,7 +398,7 @@ impl Error { Error::new_user(User::Body).with(cause) } - #[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))] + #[cfg(all(feature = "client", feature = "http2"))] pub(super) fn new_user_invalid_connect() -> Error { Error::new_user(User::InvalidConnectWithBody) } @@ -500,7 +500,7 @@ impl Error { feature = "ffi" ))] Kind::User(User::BodyWriteAborted) => "user body write aborted", - #[cfg(all(any(feature = "client", feature = "server"), feature = "http2"))] + #[cfg(all(feature = "client", feature = "http2"))] Kind::User(User::InvalidConnectWithBody) => { "user sent CONNECT request with non-zero body" }