Skip to content

Commit 090ee08

Browse files
committed
refactor(http1): reject newlines in chunked extensions
We don't really care what bytes are in chunked extensions. We ignore them until we find a CRLF. However, some other HTTP implementations may only look for a LF, and forget that chunked requires the CR as well. To save them from themselves, this makes hyper reject any chunked extensions that include an LF byte. This isn't a *bug*. No one ever cares what's in the extensions. This is meant as a way to help implementations that don't decoded chunked encoding correctly. This shouldn't affect really anyone in the real world.
1 parent 52214f3 commit 090ee08

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/proto/h1/decode.rs

+11
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,18 @@ impl ChunkedState {
268268
rdr: &mut R,
269269
) -> Poll<Result<ChunkedState, io::Error>> {
270270
trace!("read_extension");
271+
// We don't care about extensions really at all. Just ignore them.
272+
// They "end" at the next CRLF.
273+
//
274+
// However, some implementations may not check for the CR, so to save
275+
// them from themselves, we reject extensions containing plain LF as
276+
// well.
271277
match byte!(rdr, cx) {
272278
b'\r' => Poll::Ready(Ok(ChunkedState::SizeLf)),
279+
b'\n' => Poll::Ready(Err(io::Error::new(
280+
io::ErrorKind::InvalidData,
281+
"invalid chunk extension contains newline",
282+
))),
273283
_ => Poll::Ready(Ok(ChunkedState::Extension)), // no supported extensions
274284
}
275285
}
@@ -537,6 +547,7 @@ mod tests {
537547
read_err("1 invalid extension\r\n", InvalidInput).await;
538548
read_err("1 A\r\n", InvalidInput).await;
539549
read_err("1;no CRLF", UnexpectedEof).await;
550+
read_err("1;reject\nnewlines\r\n", InvalidData).await;
540551
// Overflow
541552
read_err("f0000000000000003\r\n", InvalidData).await;
542553
}

0 commit comments

Comments
 (0)