From 6bd33067d93b78faf2deaa1d0bc61219d1c3fdaf Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 24 Oct 2026 04:15:30 -0500 Subject: [PATCH 1/2] fix: enforce completed HTTP header size limit Source reviewed and diff checks pass. Rust compile and runtime regressions NOT_RUN. Co-authored-by: Drake Stapleton --- src/tls.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/tls.rs b/src/tls.rs index e8da76f..5c48e2d 100644 --- a/src/tls.rs +++ b/src/tls.rs @@ -81,6 +81,10 @@ fn read_head(s: &mut S) -> Option> { } buf.extend_from_slice(&chunk[..n]); if let Some(i) = buf.windows(4).position(|w| w == b"\r\n\r\n") { + // Bound the complete wire head, not body bytes read in the same chunk. + if i + 4 > MAX_HEAD { + return None; + } buf.truncate(i + 2); return Some(buf); } @@ -216,6 +220,45 @@ mod tests { } } + #[test] + fn head_size_limit_includes_terminator() { + for size in [MAX_HEAD - 1, MAX_HEAD, MAX_HEAD + 1, MAX_HEAD + 2048] { + let mut head = b"GET /health HTTP/1.1\r\nX-Pad: ".to_vec(); + head.resize(size - 4, b'a'); + head.extend_from_slice(b"\r\n\r\n"); + let result = read_head(&mut std::io::Cursor::new(&head)); + if size <= MAX_HEAD { + assert_eq!(result.as_deref(), Some(&head[..size - 2]), "size {size}"); + } else { + assert!(result.is_none(), "accepted oversized head: {size}"); + } + } + } + + #[test] + fn head_size_limit_ignores_trailing_body() { + struct Chunked<'a>(&'a [u8]); + impl Read for Chunked<'_> { + fn read(&mut self, buf: &mut [u8]) -> std::io::Result { + let limit = buf.len().min(1000); + self.0.read(&mut buf[..limit]) + } + } + let mut input = b"GET /health HTTP/1.1\r\nX-Pad: ".to_vec(); + input.resize(MAX_HEAD - 104, b'a'); + input.extend_from_slice(b"\r\n\r\n"); + let head_end = input.len(); + input.extend_from_slice(&[b'b'; 4096]); + // The last read crosses MAX_HEAD, but the terminator precedes that limit. + let result = read_head(&mut Chunked(&input)); + assert_eq!(result.as_deref(), Some(&input[..head_end - 2])); + } + + #[test] + fn head_size_limit_rejects_unterminated_input() { + assert!(read_head(&mut std::io::Cursor::new(vec![b'a'; MAX_HEAD + 1])).is_none()); + } + #[test] fn head_parsing() { let h = b"GET /x?y=1 HTTP/1.1\r\nHost: a\r\nauthorization: Bearer t \r\n"; From 6a473d6e3efba591072afe409a51e8fd27c1f22f Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Sat, 24 Oct 2026 17:11:23 -0500 Subject: [PATCH 2/2] deps: rustls-webpki 0.103.15 -> 0.103.16 (RUSTSEC-2026-0382) cargo audit on the #9/#10 stack: 1 vulnerability (rustls-webpki 0.103.15, certificate verification may accept distrusted intermediates, fixed in >=0.103.16). Lockfile-only bump; cargo audit clean, cargo test 20/0, clippy -D warnings clean. Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 181016c..bc72201 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -326,9 +326,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.103.15" +version = "0.103.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3c3cf1d8b1e7d4927e2d154c3fcb02979afb9939629c62cd9048d4f07b60ac2" +checksum = "4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281" dependencies = [ "ring", "rustls-pki-types",