HTTP/2 send window blocks can be deferred indefinitely by a WINDOW_UPDATE trickle
Description
The fix for GHSA-xj8g-532w-jv94 (#671) added a 15-second wall-clock bound (@pending_send_timeout) on how long an HTTP/2 stream may sit blocked on the connection send window, so a peer cannot pin a blocked stream process (and the Plug state and resources it holds) indefinitely. Its own note in connection.ex states this value also bounds a block on the stream send window, "so that neither path can pin a stream process … indefinitely."
In fact both send-window blocks reset their deadline whenever the peer makes partial progress, so a peer that drips tiny WINDOW_UPDATE frames keeps either block alive for as long as it keeps dripping:
- Connection level (the block #671 addressed): a partially-advanced send is re-queued in
pending_sendswith a fresh deadline, so aWINDOW_UPDATEon stream 0 resets the clock on every drip. - Stream level: the block is a recursive
receive ... after read_timeout; on each streamWINDOW_UPDATEit recurses and re-arms a freshread_timeout, so aWINDOW_UPDATEon the stream resets the clock on every drip.
Either reopens the resource exhaustion condition GHSA-xj8g-532w-jv94 was assigned for. The stream-level path is independently reachable and is not closed by fixing only the connection level one.
Affected versions
All releases up to and including 1.12.5.
- The connection level path was introduced by the bound added for GHSA-xj8g-532w-jv94, which first shipped in 1.12.5. Earlier releases have no bound at all on a connection-level block, so they are exposed to the original GHSA-xj8g-532w-jv94 condition instead.
- The stream level path exists in every release since the HTTP/2 refactor.
Severity
Proposed: High, matching the parent advisory, for both paths. GHSA-xj8g-532w-jv94 is scored CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H (7.5), and this reopens the same impact a remote, unauthenticated peer causes resource pinning / exhaustion with no confidentiality or integrity effect. A single connection can hold many concurrent streams (up to max_concurrent_streams), each pinnable this way, multiplying the retained process/memory footprint.
- CWE-400: Uncontrolled Resource Consumption
- Related: CWE-770 (Allocation of Resources Without Limits or Throttling)
Details
Connection-level block (lib/bandit/http2/connection.ex)
The bound is enforced by expire_pending_sends/1, called whenever data arrives on the connection, which drops any queued send whose expires_at has passed. The deadline is set in finish_data, reached both when a send is first queued and when a partially advanced send is re-queued from do_pending_sends/2:
defp finish_data(stream_id, rest, end_stream, on_unblock, connection) do
expires_at = :erlang.monotonic_time(:millisecond) + @pending_send_timeout
...
enddo_pending_sends/2 runs on every WINDOW_UPDATE. When the update grants fewer bytes than remain queued, the leftover rest is re-queued and finish_data recomputes expires_at from now rather than preserving the original. So each partial advance restarts the timer, and expires_at <= now is never true while the drip continues.
A connection-level block is also re-queued, with a fresh deadline, by any SETTINGS frame (including an empty one), because handle_frame/3 for SETTINGS also calls do_pending_sends/2. This variant needs no WINDOW_UPDATE credit at all, so the stream does not have to make even token progress.
Stream-level block (lib/bandit/http2/stream.ex)
send_data/3, running in the stream process, blocks on the stream send window with a recursive receive:
receive do
{:bandit, {:send_window_update, delta}} ->
stream |> do_recv_send_window_update(delta) |> send_data(rest, end_stream)
{:bandit, {:rst_stream, error_code}} ->
do_recv_rst_stream!(stream, error_code)
after
stream.read_timeout ->
stream_error!("Timeout waiting for space in the send_window", stream, ...)
endOn a stream WINDOW_UPDATE it recurses into send_data(rest, end_stream), which re-enters and re-arms a fresh after stream.read_timeout. read_timeout is the hardcoded struct default of 15_000 (never overridden in init/5). So each partial advance restarts the 15s timer and the block never fires while the drip continues.
For this block (rather than the connection level one) to be the one stuck, the stream send window must be exhausted while the connection window has room. The peer controls both: a large WINDOW_UPDATE on stream 0 opens the connection window wide, and a small SETTINGS_INITIAL_WINDOW_SIZE shrinks the per-stream window.
Impact
A remote, unauthenticated peer elicits a server response larger than the relevant send window (so the send blocks), then sends a slow trickle of small WINDOW_UPDATE frames, a few bytes each, one every several seconds. Each frame makes token forward progress while resetting the deadline, so the blocked stream process (and any Plug state, upstream connections, file handles, or other resources it holds mid-response) is retained indefinitely instead of being released after 15 seconds. Repeated across many concurrent streams on one or more connections, this exhausts server processes and memory. The denial-of-service GHSA-xj8g-532w-jv94 was intended to bound.
The trickle also defeats the transport-level read timeout, since the connection is continuously receiving valid frames. And note the two paths are independent: closing only the connection level block still leaves the stream level block fully exploitable, since a peer can hold the connection window wide open and pin the stream on its per-stream window instead.
Proof of concept (conceptual)
Connection-level:
- Open a stream whose response exceeds the connection send window (65,535 B).
- The server blocks and queues the remainder in
pending_sends. - Drip
WINDOW_UPDATE(stream 0, 1)every ~10s. Each re-queues the rest with a fresh deadline;expire_pending_sendsnever expires it.
Stream-level:
- Send
WINDOW_UPDATE(stream 0, large)so the connection window never blocks. - Advertise a small
SETTINGS_INITIAL_WINDOW_SIZEso the per-stream window is tiny. - Request a large response; the server sends the stream-window's worth, then blocks in the recursive
receive. - Drip
WINDOW_UPDATE(stream N, 1)every <15s. Each re-arms a freshread_timeout. Stream pinned indefinitely; repeat across streams.
Patches
The deadline on a blocked send now starts when the send first blocks, and is no longer reset when the peer makes progress. It is pushed back only in proportion to the bytes the peer actually lets the server send (one second per KiB, and never beyond the base timeout from the current time). A peer that dribbles window increments, or that sends frames which grant no window, therefore no longer keeps a send blocked beyond the base timeout. A client that drains a send at 1 KiB/s or faster is never cut off, regardless of how large the send is. The same bound is applied at both the connection level and the stream level. No new configuration option is introduced.
Note that a peer which genuinely reads at the minimum rate can still hold a stream open for as long as the response lasts; this is inherent to serving slow readers and is not addressed by this advisory.
Workarounds
There is no configuration workaround. Deployments can mitigate by terminating HTTP/2 at a reverse proxy that enforces its own send timeouts, or by disabling HTTP/2 with http_2_options: [enabled: false].