Skip to content

fix(http1): drop trailers when the peer speaks HTTP/1 instead of crashing - #8628

Open
ToniAdreal wants to merge 1 commit into
mitmproxy:mainfrom
ToniAdreal:fix-8573-h1-trailers
Open

ToniAdreal wants to merge 1 commit into
mitmproxy:mainfrom
ToniAdreal:fix-8573-h1-trailers

Conversation

@ToniAdreal

Copy link
Copy Markdown

Fixes #8573.

HttpLayer forwards request/response trailers to the peer's protocol layer whenever flow.request.trailers / flow.response.trailers is set, but Http1Client.send / Http1Server.send had no branch for trailer events and fell through to raise AssertionError. An h2/h3 peer sending legal trailers therefore crashed the stream whenever the other side was HTTP/1, and the upstream connection was left in read_body state (RequestEndOfMessage never dispatched).

This drops RequestTrailers in Http1Client.send and ResponseTrailers in Http1Server.send. Trailers are optional metadata, and HTTP/1.1 only supports them as a chunked trailer section, which we do not emit, so dropping is the correct behaviour for content-length bodies. The RequestEndOfMessage / ResponseEndOfMessage that follows still runs mark_done, so the connection stays reusable.

Verified locally (main @ f7701d5):

  • Reproduced the crash before the fix: the two new regression tests fail on unpatched code (AssertionError: Playbook mismatch!, the trailer event falls through to raise AssertionError).
  • After the fix, the two new regression tests in test/mitmproxy/proxy/layers/http/test_http_version_interop.py (test_h2_request_trailers_to_h1, test_h1_response_trailers_from_h2) pass, and the existing test_http_version_interop.py (4 passed) and test_http2.py / test_http1.py (59 passed) still pass.
  • ruff check and ruff format --check pass on the touched files.
  • CHANGELOG entry added under "Unreleased: mitmproxy next".

Not done here (possible follow-up): emitting trailers as a chunked trailer section when the body was sent chunked, and replacing the blanket raise AssertionError in send() with a logged protocol error.

…hing

Fixes mitmproxy#8573.

HttpLayer forwards request/response trailers to the peer's protocol
layer whenever flow.request.trailers / flow.response.trailers is set,
but Http1Client.send / Http1Server.send had no branch for trailer
events and fell through to raise AssertionError. An h2/h3 peer sending
legal trailers therefore crashed the stream whenever the other side was
HTTP/1, and the upstream connection was left in read_body state
(RequestEndOfMessage never dispatched).

This drops RequestTrailers in Http1Client.send and ResponseTrailers in
Http1Server.send. Trailers are optional metadata, and HTTP/1.1 only
supports them as a chunked trailer section, which we do not emit, so
dropping is the correct behaviour for content-length bodies. The
RequestEndOfMessage / ResponseEndOfMessage that follows still runs
mark_done, so the connection stays reusable.

Signed-off-by: ToniAdreal <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTP/2/3 trailers forwarded to an HTTP/1 peer crash the stream (AssertionError)

1 participant