Repository navigation
fix(http2): strip TE request header when any value is not trailers - #4194
Dev-next-gen wants to merge 2 commits into
Conversation
Only the first TE value was checked before sending an HTTP/2 request, so a request with `TE: trailers` followed by another TE line kept both values and the peer reset the stream with PROTOCOL_ERROR. Check every value, as the HTTP/1 side already does since hyperium#4152.
There was a problem hiding this comment.
The bug is real — get only looks at the first field line, so TE: trailers followed by TE: gzip reaches the peer as an HTTP/2-invalid TE (RFC 9113 §8.2.2). Switching to get_all(...).iter().any(...) is the right fix.
Two non-blocking things:
-
The comparison is still byte-wise against
"trailers". TE is a list field (RFC 9110 §10.1.4) andtrailersis a case-insensitive literal, soTE: TrailersandTE: trailers, trailersare both valid but currently stripped. Splitting each field line on commas, trimming OWS and comparing each member case-insensitively would cover both. We already do that on the HTTP/1 side in #4152. -
Can we add a positive test? Two
TE: trailersfield lines should survive — that's the exact case this PR adds, and the current test only covers the invalid one.
Otherwise looks good to me.
Cover the case the previous commit allows: two `TE: trailers` lines must both reach the peer, not be stripped.
|
The positive case was missing, you're right. de8bd47 moves the h2 client/server setup into a small helper and adds On the first point, I tried your change before answering, and I don't think hyper can keep those values. h2 compares TE byte-for-byte against Found by a defect-hunting pipeline I build and run (Dev-next-gen), using Claude Code with Anthropic's Claude Opus 5.5. |
|
Thanks for testing this against h2 — that makes sense. I hadn't accounted for its byte-wise validation on both the send and receive paths, so keeping the exact comparison is the right call with the current implementation. And thanks for adding the positive test for repeated |
After #4152 made the HTTP/1 side look at every TE line and every token, I checked the HTTP/2 path and found that
strip_connection_headersstill only reads the first TE value before sending a request. WithTE: trailersfollowed by a second line likeTE: gzip, the first value passes, nothing gets stripped, and h2's own send check also only looks at the first value, so both lines go out. The receiving side validates each field on its own, so the peer resets the stream with PROTOCOL_ERROR. Between two hyper peers,send_requestreturnsReset(StreamId(1), PROTOCOL_ERROR, Remote).The fix checks every TE value, and if any of them is not
trailersthe header is removed, which is what already happens when a single TE value is nottrailers. Requests that worked before (no TE, or oneTE: trailers) behave the same. The only requests that change are the ones that were always reset.I added an integration test with a hyper h2 client and server. It fails on master with the reset above and passes with the change. The integration, lib, client and server test suites pass locally with
--features full, as docargo fmt --checkandcargo clippy --features full.AI tools used