Repository navigation
Description
Problem
With h2 = 0.4.19, a client accepts a response HEADERS frame with an empty HPACK block and END_HEADERS | END_STREAM, even though no :status was sent. ResponseFuture resolves successfully with 200 OK and an empty header map.
Observed in the published 0.4.19 source (VCS commit d57d1b852fec9dda6d42d3454502006d52104da8), on Rust 1.98.0/Linux. The reproducer uses only an in-memory Tokio duplex stream: no TLS, DNS, proxy, or external server is involved.
Expected and actual behavior
RFC 9113 §8.3.2 requires :status in every response; a missing field makes the response malformed. I expect a protocol error rather than a synthesized successful status.
Actual output:
status=200 OK, headers={}
This was found while checking HTTP health probes: a consumer validating response.status() cannot distinguish this synthesized 200 from an actual status received from the peer. No broader security impact is claimed here.
Reproducer
Dependencies for cargo run:
[dependencies]
h2 = "=0.4.19"
http = "1"
tokio = { version = "1", features = ["macros", "rt", "io-util", "time"] }src/main.rs:
use std::time::Duration;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (io, mut peer) = tokio::io::duplex(4096);
let server = tokio::spawn(async move {
let mut preface = [0; 24];
peer.read_exact(&mut preface).await.unwrap();
peer.write_all(&[0, 0, 0, 4, 0, 0, 0, 0, 0]).await.unwrap();
loop {
let mut header = [0_u8; 9];
peer.read_exact(&mut header).await.unwrap();
let length = ((header[0] as usize) << 16)
| ((header[1] as usize) << 8)
| header[2] as usize;
let mut payload = vec![0; length];
peer.read_exact(&mut payload).await.unwrap();
if header[3] == 4 && header[4] == 0 {
peer.write_all(&[0, 0, 0, 4, 1, 0, 0, 0, 0]).await.unwrap();
}
if header[3] == 1 {
// Empty HPACK block: END_HEADERS | END_STREAM, no :status.
let mut response = [0_u8; 9];
response[3] = 1;
response[4] = 5;
response[5..].copy_from_slice(&header[5..]);
peer.write_all(&response).await.unwrap();
std::future::pending::<()>().await;
}
}
});
let (mut client, connection) = h2::client::handshake(io).await?;
let driver = tokio::spawn(async move { let _ = connection.await; });
let request = http::Request::builder()
.uri("http://example.test/")
.body(())?;
let (response, _) = client.send_request(request, true)?;
let response = tokio::time::timeout(Duration::from_secs(1), response).await??;
println!("status={}, headers={:?}", response.status(), response.headers());
drop(response);
drop(client);
driver.abort();
let _ = driver.await;
server.abort();
let _ = server.await;
Ok(())
}Suspected cause
Peer::convert_poll_message only sets the response status when pseudo.status is Some; otherwise http::Response::builder() retains its default 200. Requiring the pseudo-header before constructing the response appears to be the relevant boundary. I also found the optional assignment in current master when inspecting the source, but only the published 0.4.19 build was executed.
Disclosure: this report and reproducer were prepared with LLM assistance; the reproducer above was compiled and run locally.
Activity
Fix missing response status (hyperium#958)
fix(client): reject responses without `:status` (hyperium#959)
fix(client): reject responses without `:status` (hyperium#959)