Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion rpxy-lib/src/message_handler/handler_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
name_exp::ServerName,
};
use derive_builder::Builder;
use http::{Request, Response, StatusCode};
use http::{Method, Request, Response, StatusCode};
use hyper_util::{client::legacy::connect::Connect, rt::TokioIo};
use std::{net::SocketAddr, sync::Arc};
use tokio::io::copy_bidirectional;
Expand Down Expand Up @@ -90,6 +90,11 @@ where
tls_enabled: bool,
tls_server_name: Option<ServerName>,
) -> HttpResult<Response<ResponseBody>> {
// Block CONNECT requests because a) makes no sense to run a forward proxy behind a reverse proxy = fringe use case b) might have serious security implications for badly configured upstreams c) it doesn't work with current implementation (bodies are not forwarded)
if matches!(*req.method(), Method::CONNECT) {
return Err(HttpError::UnsupportedMethod);
}

// Here we start to inspect and parse with server_name
let server_name = req
.inspect_parse_host()
Expand Down
3 changes: 3 additions & 0 deletions rpxy-lib/src/message_handler/http_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ pub(crate) type HttpResult<T> = std::result::Result<T, HttpError>;
pub enum HttpError {
// #[error("No host is give in request header")]
// NoHostInRequestHeader,
#[error("Unsupported method")]
UnsupportedMethod,
#[error("Invalid host in request header")]
InvalidHostInRequestHeader,
#[error("SNI and Host header mismatch")]
Expand Down Expand Up @@ -44,6 +46,7 @@ impl From<HttpError> for StatusCode {
fn from(e: HttpError) -> StatusCode {
match e {
// HttpError::NoHostInRequestHeader => StatusCode::BAD_REQUEST,
HttpError::UnsupportedMethod => StatusCode::METHOD_NOT_ALLOWED,
HttpError::InvalidHostInRequestHeader => StatusCode::BAD_REQUEST,
HttpError::SniHostInconsistency => StatusCode::MISDIRECTED_REQUEST,
HttpError::NoMatchingBackendApp => StatusCode::SERVICE_UNAVAILABLE,
Expand Down