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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure authority and/or host fields are not empty #232

Merged
merged 3 commits into from
Jun 1, 2024
Merged
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
44 changes: 39 additions & 5 deletions h3/src/proto/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ impl Header {
//# request MUST contain either an :authority pseudo-header field or a
//# Host header field.

//= https://www.rfc-editor.org/rfc/rfc9114#section-4.3.1
//= type=TODO
//# If these fields are present, they MUST NOT be
//# empty.

//= https://www.rfc-editor.org/rfc/rfc9114#section-4.3.1
//= type=TODO
//# If the scheme does not have a mandatory authority component and none
Expand All @@ -99,6 +94,10 @@ impl Header {

Ok((
self.pseudo.method.ok_or(HeaderError::MissingMethod)?,
// When empty host field is built into a uri it fails
//= https://www.rfc-editor.org/rfc/rfc9114#section-4.3.1
//# If these fields are present, they MUST NOT be
//# empty.
uri.build().map_err(HeaderError::InvalidRequest)?,
self.pseudo.protocol,
self.fields,
Expand Down Expand Up @@ -291,6 +290,9 @@ impl Field {

Ok(match name {
b":scheme" => Field::Scheme(try_value(name, value)?),
//= https://www.rfc-editor.org/rfc/rfc9114#section-4.3.1
//# If these fields are present, they MUST NOT be
//# empty.
b":authority" => Field::Authority(try_value(name, value)?),
b":path" => Field::Path(try_value(name, value)?),
b":method" => Field::Method(
Expand Down Expand Up @@ -498,6 +500,38 @@ mod tests {
);
}

#[test]
fn request_has_empty_authority() {
//= https://www.rfc-editor.org/rfc/rfc9114#section-4.3.1
//= type=test
//# If these fields are present, they MUST NOT be
//# empty.
assert_matches!(
Header::try_from(vec![
(b":method", Method::GET.as_str()).into(),
(b":authority", b"").into(),
]),
Err(HeaderError::InvalidHeaderValue(_))
);
}

#[test]
fn request_has_empty_host() {
//= https://www.rfc-editor.org/rfc/rfc9114#section-4.3.1
//= type=test
//# If these fields are present, they MUST NOT be
//# empty.
let headers = Header::try_from(vec![
(b":method", Method::GET.as_str()).into(),
(b"host", b"").into(),
])
.unwrap();
assert_matches!(
headers.into_request_parts(),
Err(HeaderError::InvalidRequest(_))
);
}

#[test]
fn request_has_authority() {
//= https://www.rfc-editor.org/rfc/rfc9114#section-4.3.1
Expand Down
Loading