Skip to content

Limit buffered QUIC ClientHello data for incomplete handshakes - #8640

Open
orshih6 wants to merge 3 commits into
mitmproxy:mainfrom
orshih6:contribot/issue-8619
Open

orshih6 wants to merge 3 commits into
mitmproxy:mainfrom
orshih6:contribot/issue-8619

Conversation

@orshih6

@orshih6 orshih6 commented Nov 21, 2026

Copy link
Copy Markdown

ClientQuicLayer adds every Initial datagram to handshake_datagram_buf. Each time one arrives, it re-parses the whole buffer with a fresh aioquic connection. If a client keeps sending valid but incomplete Initials on one UDP tuple, the buffer never stops growing and the parsing work grows roughly quadratically. That can stall the proxy for other clients.

This change adds MAX_CLIENT_HELLO_DATAGRAM_BYTES (64 KiB) to cap how much Initial data is buffered while waiting for a complete ClientHello. That is still plenty for fragmented ClientHellos, including large post-quantum ones. When the cap is exceeded, the buffer is cleared and the handshake fails. This uses the existing "Cannot parse ClientHello" error path, which logs a warning, fires tls_failed_client and closes the connection. Since every datagram is at least 1200 bytes, this also bounds the number of replays per tuple.

The full incremental parser suggested in the issue is not part of this change. Keeping one QuicConnection across calls would mean reworking the monkeypatching in _client_hello_parser.py, and the cap already bounds the work.

Testing: I added test_clienthello_too_large. It lowers the limit so that a legitimately fragmented ClientHello exceeds it, then checks that the connection is closed and the buffer is cleared. The existing fragmented-ClientHello tests still pass with the default limit. test/mitmproxy/proxy/layers/quic/ passes with 100% coverage of _stream_layers.py, and ruff and mypy are clean.

🤖 Generated with Claude Code

Fixes #8619


This change was prepared with an AI coding agent (Claude) and reviewed by me before submitting. I'm happy to make any changes you'd like.

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.

Bound QUIC ClientHello inspection work for incomplete handshakes

1 participant