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 1 commit
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 @@ -202,6 +201,9 @@ impl Iterator for HeaderIter {
}
}

//= https://www.rfc-editor.org/rfc/rfc9114#section-4.3.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far. Do you mind moving that comment to the Field::parse method? The parse method will return the error when authority is empty. So one can find the location when looking through the compliance report.
iirc the error comes from here:

b":authority" => Field::Authority(try_value(name, value)?),

//# If these fields are present, they MUST NOT be
//# empty.
impl TryFrom<Vec<HeaderField>> for Header {
type Error = HeaderError;
fn try_from(headers: Vec<HeaderField>) -> Result<Self, Self::Error> {
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