You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unbounded buffering: HTTP/1 head (client, upstream, CONNECT-proxy) and WebSocket messages #8574
HTTP/1 request and response heads are buffered without any size limit: Http1Connection.read_headers keeps appending to self.buf (h11.ReceiveBuffer) until a blank line terminates the head. A peer that never sends \r\n\r\n can grow the buffer arbitrarily per connection. This affects:
mitmproxy/proxy/layers/http/_http1.py:319 (client request head — already marked # FIXME: protect against header size DoS),
mitmproxy/proxy/layers/http/_http1.py:435 (upstream response head — same FIXME),
mitmproxy/proxy/layers/http/_upstream_proxy.py:91-92 (CONNECT response head from an upstream proxy — same maybe_extract_lines loop, so a malicious/compromised upstream proxy can do the same to mitmproxy).
The same unbounded-buffering pattern exists for WebSocket messages: WebsocketLayer.relay_messages (mitmproxy/proxy/layers/websocket.py:172-194) accumulates all fragments of a message into frame_buf and joins them before the websocket_message hook runs — a client or upstream can send an arbitrarily large message (wsproto has no message-size limit; permessage-deflate payloads additionally inflate), all buffered.
Result: srv.buf holds 50 MB, state is still read_headers, no error, no cap. Growth is monotonic in bytes received; multiply by N connections for linear memory amplification.
Impact
Any client that can reach a listener (any proxy mode) can make mitmproxy buffer unlimited bytes per connection without authentication; a malicious upstream server or upstream HTTP proxy can do the same on the response side. Since the head never terminates, body_size_limit/stream_large_bodies cannot help — they only apply to bodies. Similarly, no option bounds a WebSocket message.
Suggestion
Cap the head buffer (e.g. 64 KiB, ideally an option) in the else: branch of read_headers — exceed → 431/502 + CloseConnection.
Apply the same cap to the upstream-proxy handshake reader.
Bound frame_buf in the WebSocket layer (option, kill/forward-behavior on exceed).
Activity