Skip to content

Commit 5196a65

Browse files
authored
Block leading and trailing whitespace in field values
This blocks header values with leading and trailing whitespace. This is not needed for HTTP/1.x where the parser already strips such whitespace, but in HTTP/2 and HTTP/3 the parser does not strip such whitespace and so it is up to the `http` crate to reject such headers. Different HTTP/2 and HTTP/3 libraries treat such values differently, so rejection is the safest option. Fixes #245
1 parent 8c1fb20 commit 5196a65

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/header/value.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,14 @@ impl HeaderValue {
241241
src: T,
242242
into: F,
243243
) -> Result<HeaderValue, InvalidHeaderValue> {
244-
for &b in src.as_ref() {
244+
let u8_slice = src.as_ref();
245+
match u8_slice {
246+
[b' ', ..] | [b'\t', ..] | [.., b' '] | [.., b'\t'] => {
247+
return Err(InvalidHeaderValue { _priv: () })
248+
}
249+
_ => (),
250+
};
251+
for &b in u8_slice {
245252
if !is_valid(b) {
246253
return Err(InvalidHeaderValue { _priv: () });
247254
}

0 commit comments

Comments
 (0)