Skip to content

Commit a0816ed

Browse files
committed
Deny requerst if :authority field is invalid only with CONNECT method
Copied-from: hyperium#612
1 parent ef743ec commit a0816ed

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/server.rs

+21-7
Original file line numberDiff line numberDiff line change
@@ -1527,13 +1527,27 @@ impl proto::Peer for Peer {
15271527
// header
15281528
if let Some(authority) = pseudo.authority {
15291529
let maybe_authority = uri::Authority::from_maybe_shared(authority.clone().into_inner());
1530-
parts.authority = Some(maybe_authority.or_else(|why| {
1531-
malformed!(
1532-
"malformed headers: malformed authority ({:?}): {}",
1533-
authority,
1534-
why,
1535-
)
1536-
})?);
1530+
1531+
// `:authority` is required only with `CONNECT` method.
1532+
// It should contains host and port. This is exactly what `uri::Authority` is
1533+
// going to parse.
1534+
//
1535+
// See: https://datatracker.ietf.org/doc/html/rfc7540#section-8.3
1536+
if is_connect {
1537+
if let Err(why) = &maybe_authority {
1538+
malformed!(
1539+
"malformed headers: malformed authority ({:?}): {}",
1540+
authority,
1541+
why,
1542+
);
1543+
}
1544+
}
1545+
1546+
// `authority` is not required in HTTP/2, so it is safe to keep it `None`
1547+
// in `parts`.
1548+
//
1549+
// See: https://datatracker.ietf.org/doc/html/rfc7540#section-8.1.2.3
1550+
parts.authority = maybe_authority.ok();
15371551
}
15381552

15391553
// A :scheme is required, except CONNECT.

0 commit comments

Comments
 (0)