Skip to content

Commit

Permalink
Merge pull request #27 from Volham22/reject-uppercase-headers
Browse files Browse the repository at this point in the history
fix(http2): Reject uppercase headers
  • Loading branch information
Volham22 authored Apr 5, 2024
2 parents 7288876 + 84bd79e commit b2a854e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/connection/http2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ pub async fn do_connection_loop(
// RFC 9113 6.1: `If a DATA frame is received whose Stream
// Identifier field is 0x00, the recipient MUST respond with a
// connection error`
if frame.stream_identifier == 0 {
if frame.stream_identifier == 0 && frame.length > 0 {
return Err(ConnectionError::DataOnStreamZero);
}

Expand Down
2 changes: 2 additions & 0 deletions src/http2/frames/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub enum FrameError {
WindowUpdateTooBig,
#[error("Frame is too big ({actual} > {max_frame_size})")]
FrameTooBig { actual: u32, max_frame_size: u32 },
#[error("Header frame contains uppercase header")]
UppercaseHeader,
// #[error("Continuation frame without header frame")]
// ContinuationWithoutHeader,
// #[error("Continuation frame but END_HEADERS set")]
Expand Down
11 changes: 10 additions & 1 deletion src/http2/frames/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,16 @@ impl Headers {
headers: hds
.into_iter()
.map(|(k, v)| (Bytes::from(k), Bytes::from(v)))
.collect(),
.map(|(k, v)| {
if k.iter()
.all(|c| c.is_ascii_uppercase() || c.is_ascii_punctuation())
{
Err(FrameError::UppercaseHeader)
} else {
Ok((k, v))
}
})
.collect::<Result<Vec<(Bytes, Bytes)>, FrameError>>()?,
end_stream: Self::is_end_stream(flags),
}),
Err(err) => {
Expand Down

0 comments on commit b2a854e

Please sign in to comment.