Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deny requerst if :authority field is invalid only with CONNECT method #612

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 21 additions & 7 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1527,13 +1527,27 @@ impl proto::Peer for Peer {
// header
if let Some(authority) = pseudo.authority {
let maybe_authority = uri::Authority::from_maybe_shared(authority.clone().into_inner());
parts.authority = Some(maybe_authority.or_else(|why| {
malformed!(
"malformed headers: malformed authority ({:?}): {}",
authority,
why,
)
})?);

// `:authority` is required only with `CONNECT` method.
// It should contains host and port. This is exactly what `uri::Authority` is
// going to parse.
//
// See: https://datatracker.ietf.org/doc/html/rfc7540#section-8.3
if is_connect {
if let Err(why) = &maybe_authority {
malformed!(
"malformed headers: malformed authority ({:?}): {}",
authority,
why,
);
}
}

// `authority` is not required in HTTP/2, so it is safe to keep it `None`
// in `parts`.
//
// See: https://datatracker.ietf.org/doc/html/rfc7540#section-8.1.2.3
parts.authority = maybe_authority.ok();
}

// A :scheme is required, except CONNECT.
Expand Down