Skip to main content
Menu
Advisories

Mint HTTP/2 client buffers oversized frames to ~16 MiB before enforcing max_frame_size, enabling remote memory exhaustion

GHSA-Q95C-CCQ6-J5J6Published Updated GitHub

Description

Mint's HTTP/2 client enforces its max_frame_size limit only after a complete frame payload has been received, not against the length field in the 9-byte frame header. Because the frame decoder pattern-matches on the full declared payload before the size guard can run, a malicious or compromised HTTP/2 server can announce a frame whose declared length is far larger than the client's advertised max_frame_size (default 16,384 bytes, header maximum 16,777,215 bytes) and then stream that payload slowly. The client accumulates every received byte in a per-connection buffer while the decoder repeatedly returns an incomplete-frame signal, so the buffer for a single connection can grow to roughly 16 MiB, about 1024 times the advertised limit, and can be pinned there indefinitely. Any Elixir or Erlang service that uses Mint as an HTTP/2 client against an untrusted or attacker-influenced origin is exposed with no application opt-in.

Root Cause

The security invariant Mint intends to enforce is that no inbound frame exceeds the negotiated max_frame_size. That check is expressed as a guard on the decoded payload rather than on the declared length field, so it cannot fire until the whole payload is already buffered. The frame decoder uses an Erlang binary pattern match that requires the entire declared payload to be present as a contiguous binary before it succeeds; until then it returns an incomplete-frame result and the caller stores the growing binary. There is no comparison of the 24-bit header length field against max_frame_size before accumulation begins, and no independent cap on the connection buffer.

# lib/mint/http2/frame.ex
def decode_next(bin, max_frame_size \\ 16_384) when is_binary(bin) do
  case decode_next_raw(bin) do
    {:ok, {_type, _flags, _stream_id, payload}, _rest}
    when byte_size(payload) > max_frame_size ->
      {:error, :payload_too_big}          # only reachable once the full payload is present
    {:ok, {type, flags, stream_id, payload}, rest} ->
      {:ok, decode_contents(type, flags, stream_id, payload), rest}
    :more ->
      :more
  end
end

defp decode_next_raw(<<
       length::24, type, flags, _reserved::1, stream_id::31,
       payload::size(length)-binary,        # requires all `length` bytes before matching
       rest::binary
     >>) do
  {:ok, {type, flags, stream_id, payload}, rest}
end

defp decode_next_raw(_other), do: :more   # returned for any partial frame
# lib/mint/http2.ex
defp maybe_concat_and_handle_new_data(conn, data) do
  data = Util.maybe_concat(conn.buffer, data)   # unconditional concatenation, no size cap
  {conn, responses} = handle_new_data(conn, data, [])
  {:ok, conn, Enum.reverse(responses)}
end

defp handle_new_data(%__MODULE__{} = conn, data, responses) do
  case Frame.decode_next(data, conn.client_settings.max_frame_size) do
    :more ->
      conn = put_in(conn.buffer, data)          # stores the growing buffer with no size guard
      handle_consumed_all_frames(conn, responses)
    ...
  end
end

Impact

The attacker must be, or must control, the HTTP/2 server that a Mint client connects to; no client-side authentication or non-default configuration is required. Once connected, the attacker can inflate the client's per-connection buffer to roughly 16 MiB and hold it there for as long as the connection stays open by withholding the final payload byte. The demonstrated capability is memory-resource exhaustion of the client process: with N connections to hostile origins the inflation is about 16 MiB times N, and transient peaks during binary concatenation can be roughly double the current buffer size. This is a remote, unauthenticated denial-of-service primitive against outbound HTTP/2 clients such as web-backend HTTP clients, webhook delivery systems, scrapers, federation and proxy components, and any client that follows redirects to third-party HTTP/2 origins. There is no bandwidth amplification: the attacker must transmit one byte for every byte the client buffers, which bounds the practical blast radius per connection but does not remove the 1024x gap between the advertised limit and actual enforcement.

Proof of Concept

The proof of concept exercises the frame decoder directly, which is the point at
which the size guard is bypassed. It shows that an oversized declared length
produces the incomplete-frame result during accumulation and only trips the size
error once the full payload is present, so the caller buffers everything in the
meantime. Requires an Elixir/OTP toolchain with the mint dependency available.
  1. Build a 9-byte HTTP/2 frame header whose 24-bit length field declares 1,000,000 bytes, which exceeds the default max_frame_size of 16,384.
  2. Feed the header plus incrementally larger partial payloads to the decoder and observe the incomplete-frame result each time.
  3. Feed the complete declared payload and observe that the size error is only raised now, after the full payload has been buffered.
max = 16_384
declared = 1_000_000
header = <<declared::24, 0, 0, 0::1, 1::31>>

# Partial payloads accumulate; guard never fires
:more = Mint.HTTP2.Frame.decode_next(header <> :binary.copy(<<0>>, 16_384), max)
:more = Mint.HTTP2.Frame.decode_next(header <> :binary.copy(<<0>>, 512_000), max)

# Only once the full declared payload is present does the guard trip
{:error, :payload_too_big} =
  Mint.HTTP2.Frame.decode_next(header <> :binary.copy(<<0>>, declared), max)
:more
:more
{:error, :payload_too_big}

A server that streams declared - 1 payload bytes and holds the connection open keeps the client in the accumulation state permanently, pinning the buffer at up to the declared size.

Attack Chain

  1. Exposure: A Mint HTTP/2 client establishes an outbound connection to a server the attacker operates or controls, completing the connection preface and SETTINGS exchange with valid parameters. HTTP/2 client support ships in every release and requires no opt-in beyond using HTTP/2.
  2. Control: The attacker fully controls the 9-byte frame header, including the 24-bit length field (up to 16,777,215), and the payload bytes streamed afterward. All of these values pass unmodified into the client's buffer and decoder.
  3. Path: Inbound socket data reaches stream/2 (or recv/3), which calls maybe_concat_and_handle_new_data/2. That unconditionally concatenates the new bytes onto conn.buffer via Util.maybe_concat/2 and calls handle_new_data/3, which calls Frame.decode_next/2.
  4. Guard: The max_frame_size guard in Frame.decode_next/2 is expressed on the decoded payload, and decode_next_raw/1 requires the entire declared payload before its binary pattern match succeeds. For any partial oversized frame the decoder returns the incomplete-frame result, so the guard is structurally unreachable during accumulation. No independent buffer cap exists.
  5. Primitive: On the incomplete-frame result, handle_new_data/3 stores the full accumulated binary back into conn.buffer with no size check, and the cycle repeats on subsequent socket data.
  6. Result: The single-connection buffer grows to roughly the declared frame length, up to about 16 MiB, roughly 1024 times the advertised max_frame_size, and stays there while the connection is held open, exhausting client process memory across enough connections.

Bypass Evidence

The only size control on the affected path is the max_frame_size guard in Frame.decode_next/2. It does not block this path because decode_next_raw/1's binary pattern match, payload::size(length)-binary, is atomic in the Erlang virtual machine: it either matches with the complete declared payload present or fails entirely and returns the incomplete-frame result. There is no intermediate state in which the header is parsed but the payload is not, so the guard cannot run until the payload is fully buffered. Nine disproof attempts were made and all failed to prevent accumulation: TCP and inet receive buffers only bound individual socket deliveries, not the cumulative connection buffer; HTTP/2 flow control applies only to DATA frames, is evaluated after a frame is decoded, is not enforced for receive-window violations in this client, and the default connection window already equals the maximum frame length; Mint has no connection idle timeout that releases the buffer; the consumed-frames handler checks only GOAWAY state; CONTINUATION header-list limits apply to a separate structure; active and passive socket modes converge on the same accumulation function; SETTINGS validation constrains parameter ranges, not subsequent frame sizes; and the buffer accumulation function performs no size check. This weakness is distinct from the previously published advisory CVE-2026-48862 (GHSA-g586-ccqf-7x4r), which concerns unbounded growth of the per-connection stream map via PUSH_PROMISE frames; that fix, released in 1.9.0, modified only the connection module and its tests and did not touch the frame decoder or the connection buffer, so it does not cover or block this path.

Affected Versions

  • Ecosystem: erlang (Hex.pm)
  • Package: mint
  • Affected range: >= 0.1.0, < 1.11.0
  • Fixed in: 1.11.0

The incomplete-frame accumulation path was added with the HTTP/2 connection in commit 596ca43, first released in 0.1.0, and is unchanged through 1.10.1. Version 1.11.0 checks the declared length in the frame header against max_frame_size before buffering the payload.

Suggested Fix

Enforce max_frame_size against the declared length field in the 9-byte frame header before buffering or decoding the payload. A minimal approach is to inspect the leading 24-bit length in Frame.decode_next/2 and return the too-big error immediately when it exceeds max_frame_size, so oversized frames are rejected from the header alone and the connection buffer can never exceed roughly max_frame_size plus the header size. The remediation must cover every caller that feeds inbound bytes into the decoder, including both active-mode stream/2 and passive-mode recv/3, since both share the same accumulation path. As an interim mitigation without a code change, operators can avoid initiating HTTP/2 connections to untrusted or attacker-influenced origins and can bound the memory of processes that hold Mint connections; there is no configuration setting that moves the enforcement point earlier.

Reported by zx (GitHub: @manus-pi).

Affected versions

References

GitHub · elixir-mint/mint