Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,40 @@ All notable changes to this project are documented here. The format follows
- The adapter's read timeout is still answered by this package as its `408` JSON-RPC
refusal: the whole-body deadline is this package's.

### Security: Bandit 1.15 or later

- The optional requirement moves from `{:bandit, "~> 1.13"}` to `{:bandit, "~> 1.15"}`. `Bandit`
published fourteen advisories against 1.13 after it shipped. Twelve, fixed in 1.14.0, cover
HTTP/2 flow control and the stream count, HPACK and SETTINGS work, 1-byte chunked and
WebSocket frames, chunk extensions that smuggle a request, `Content-Length` parsing, and the
body read timeout reset by control frames. GHSA-pxjf-g536-7r93 (1-byte HTTP/2 DATA frames)
is fixed in 1.14.1, and GHSA-j9wq-h5xx-5qx5 (logging HTTP/2 trailers) in 1.15.0. This
package's HTTP transport serves HTTP/2 by default, so a host that serves it on an older
`Bandit` is exposed. A host that has `Bandit` beside this package now resolves a fixed one;
a host on the stdio transport alone, or on another adapter, is unaffected (the dependency
stays optional). **If `mix deps.get` reports a conflict,** your own requirement holds
`Bandit` below 1.15: raise it to `"~> 1.15"`. `Bandit` 1.15 needs the same `plug`,
`thousand_island`, `hpax` and Elixir floors as 1.13. Its changes a host may see:
HTTP/2 now allows 500 concurrent streams per connection by default (set
`max_concurrent_streams` to change it), an HTTP/2 request whose `host` disagrees with
`:authority` is reset, responses under 300 bytes are not compressed, and an idle connection
process hibernates after 15 s (its CHANGELOG).
- On the new floor, the HTTP/2 residue the threat model stated is closed by the adapter. Before
`Bandit` 1.14 a stream kept open by WINDOW_UPDATE frames alone was held past `read_timeout`;
on 1.15 a stream fed WINDOW_UPDATE, PING, SETTINGS or PRIORITY frames while its body is owed
is answered `408` at the deadline, and a test per frame kind pins it. `connection_timeout:`
is unchanged and stays as the backstop: at its default the read now ends first, and a host
that sets it below `read_timeout` has a connection whose body is still owed at that deadline
closed with a `GOAWAY`, before the stream's own `408`. The README, the threat model's row and
the transport's documentation say so.
- `plug` 1.20.3 carries EEF-CVE-2026-120287, in `Plug.Parsers.MULTIPART`, and `plug_crypto`
2.2.0 carries EEF-CVE-2026-105963, in `Plug.Crypto`. This package calls neither, so its
`plug` requirement is unchanged. A host that uses them should take `plug` 1.20.4 and
`plug_crypto` 2.2.1.
- This repository's own lock moves `bandit` 1.13.1 to 1.15.0, `plug` 1.20.3 to 1.20.4,
`plug_crypto` 2.2.0 to 2.2.1 and `telemetry` 1.4.2 to 1.4.3 (and `ex_doc` to 0.40.5 for the
pages).

### Security: Bandit 1.13 or later

- The optional requirement moves from `{:bandit, "~> 1.5"}` to `{:bandit, "~> 1.13"}`, for
Expand Down
26 changes: 12 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,20 +364,18 @@ the connection is clean, and an ordinary response is possible.
less than one frame, so every DATA frame, an empty one included, returns to this clock).
Measured through a real `Bandit` listener: `408` at 300, 301, 327 ms for a 300 ms deadline
and 1,500, 1,500, 1,501 ms for 1,500 ms; over HTTP/2 a twenty-frame drip answered at the
deadline. One residue is the adapter's, stated on the threat model's row with its cost: over
HTTP/2 a stream kept open by WINDOW_UPDATE frames alone is held past the deadline by the
adapter's own wait, which nothing outside it can end through an interface the adapter
offers: one frame per deadline holds a stream process indefinitely, whatever body then
comes is refused, and each frame costs thirteen bytes with nothing accumulated. (A HEADERS
without END_STREAM held a stream the same way until `Bandit` 1.13, which resets the stream
as a malformed request; this transport hands that error back to the adapter rather than
answering it.) The stream is the adapter's to
end, but the **connection** is this package's: `connection_timeout:` (default twice
`read_timeout`) closes a connection whose body read has been held that long, with nothing
else on it still within its own deadline, using a `GOAWAY` the client can read, so the
residue is bounded in duration by this package and in count by `max_concurrent_streams`,
and its cost is per connection (the client's other streams still open on it end with the
`GOAWAY`; a host multiplexing long streams raises `connection_timeout`).
deadline. A control frame does not hold the read: on `Bandit` 1.15, this package's floor, a
stream fed WINDOW_UPDATE, PING, SETTINGS or PRIORITY frames while its body is owed is answered
`408` at the deadline (measured 2026-11-29, 301 to 329 ms for 300), and a HEADERS without
END_STREAM is reset as a malformed request, an error this transport hands back to the adapter
rather than answering it. Before `Bandit` 1.14 a WINDOW_UPDATE re-armed the adapter's own wait
and held a stream past the deadline, the residue the threat model's row recorded; a test per
frame kind now pins the bound. `connection_timeout:` (default twice `read_timeout`) closes a
connection whose body read is still waiting at that deadline, with nothing else on it still
within its own, using a `GOAWAY` the client can read: the backstop against an adapter that
holds a read again, and a bound you can set below `read_timeout`. Its cost is per connection
(the client's other streams still open on it end with the `GOAWAY`; a host multiplexing long
streams raises `connection_timeout`).
The `408` is this package's refusal: the JSON-RPC error object
every refusal carries, with `connection: close` over HTTP/1.1 as for every refusal issued
before the body is read (over HTTP/2 the stream ends with the response; the header would be a
Expand Down
2 changes: 1 addition & 1 deletion docs/threat-model.md

Large diffs are not rendered by default.

94 changes: 44 additions & 50 deletions lib/beam_mcp/transport/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,40 +75,38 @@ if Code.ensure_loaded?(Plug) do
given what remains, so a client that has sent its headers and then drips the body is
answered `408` when it lapses, however many bytes arrived and however the adapter splits
the reads (over HTTP/2 the adapter's reader is asked for less than one frame, so every
DATA frame, an empty one included, returns to this clock; a stream kept open by
WINDOW_UPDATE frames alone is held past the deadline by the adapter's own wait, which
nothing outside it can end through an interface the adapter offers: one frame per
deadline holds a stream process indefinitely, and whatever body then comes is refused;
each frame costs the client thirteen bytes and the host nothing accumulated. An
exception the adapter raises (on `Bandit` 1.13, a HEADERS without END_STREAM in the
middle of a body, a malformed request) is handed back to the adapter, which resets the
stream; it is not answered as `-32603`. The threat model states the residue, and the
two `Bandit` listener options that bound the
exposure: `http_2_options: [default_local_settings: [max_concurrent_streams: n]]`
caps the held streams per connection, `http_2_options: [enabled: false]` removes
HTTP/2 from the listener). That per-stream hold the adapter owns is bounded in
DURATION here by `:connection_timeout` below. A body must declare its
DATA frame, an empty one included, returns to this clock; a control frame does not hold
the read: on `Bandit` 1.15, this package's floor, a stream fed WINDOW_UPDATE, PING,
SETTINGS or PRIORITY frames while its body is owed is answered `408` at the deadline,
where before 1.14 a WINDOW_UPDATE re-armed the adapter's own wait and held the stream
past it. An exception the adapter raises (a HEADERS without END_STREAM in the middle of
a body, a malformed request) is handed back to the adapter, which resets the stream; it
is not answered as `-32603`. The adapter caps the streams per connection itself, 500 by
default, set with `http_2_options: [default_local_settings: [max_concurrent_streams: n]]`;
`http_2_options: [enabled: false]` removes HTTP/2 from the listener). A body must declare its
length; `transfer-encoding: chunked` is refused with `411` before the read, since a
chunked body is read chunk by chunk on a per-chunk clock that no deadline above it can
bound. The `408` is this Plug's
JSON-RPC refusal, with `connection: close` over HTTP/1.1 (over HTTP/2 the stream ends
with the response); nothing is written to the host's log for it: the adapter's own
error-level line at its read timeout no longer fires, since the deadline is this Plug's.
* `:connection_timeout`: positive integer, milliseconds, default twice `:read_timeout`.
The whole-body deadline above is a stream's; over HTTP/2 a stream held open by control
frames alone cannot be ended from outside the adapter, but its **connection** can. When
a body read has been blocked this long and nothing else on the connection is still
within its own body deadline, the connection is closed with a `GOAWAY` the client can
read (an OTP `GenServer.stop` on the socket handler, not a forged adapter message or a
reset). So the residue the adapter owns is bounded in duration by this option and in
count by `http_2_options`'s `max_concurrent_streams`. The cost is per connection: the
client's other legitimate streams still open on that connection end with it, so a host
multiplexing streams that outlive one body read raises this. Twice the read deadline by
default: one for the body to arrive, a second before a still-blocked read is taken for a
hold. A DoS control, and the host's to set: longer behind
a slow link, shorter facing the open internet. The default is a chosen number with its
reasoning beside the constant, not the adapter's default (which it was, unstated, for
two releases).
The whole-body deadline above is a stream's; this one is the stream's **connection**'s,
over HTTP/2. When a body read has been waiting this long and nothing else on the
connection is still within its own body deadline, the connection is closed with a
`GOAWAY` the client can read (an OTP `GenServer.stop` on the socket handler, not a
forged adapter message or a reset). It was built for an adapter that held a stream's
read past the read deadline, which no interface the adapter offers could end; on
`Bandit` 1.15 no client behaviour measured does, so at the default the read ends first
and this stands down. It stays as a backstop against an adapter that holds a read again,
and as a bound a host can set below `:read_timeout` to close a connection whose body is
still owed sooner than the stream's own `408` would come. The cost is per connection:
the client's other legitimate streams still open on that connection end with it, so a
host multiplexing streams that outlive one body read raises this. Twice the read
deadline by default: one for the body to arrive, a second before a still-waiting read is
taken for a hold. A DoS control, and the host's to set. The default is a chosen number
with its reasoning beside the constant, not the adapter's default (which it was,
unstated, for two releases).

The bytes are the ones the client sent, not a re-encoding of them. A signature covers
bytes, so handing a hook `Jason.encode!(Jason.decode!(body))` would break every correct
Expand Down Expand Up @@ -744,11 +742,13 @@ if Code.ensure_loaded?(Plug) do

defp read_body_bounded(conn, read_timeout, connection_timeout) do
deadline = System.monotonic_time(:millisecond) + read_timeout
# Over HTTP/2 the read can be held past its deadline by control frames alone, which no
# clock in this loop can end (029a's residue: the adapter's receive is not ours to
# interrupt). The connection is, though: a watchdog closes it at the connection deadline
# if the read is still blocked and nothing else on the connection is still within its
# own deadline. Armed only over HTTP/2; over HTTP/1 the loop below bounds every read.
# Over HTTP/2 the adapter's receive is not ours to interrupt (029a). Before Bandit 1.14
# control frames alone held it past its deadline; on 1.15, the floor, none measured does.
# The connection can be ended, though: a watchdog closes it at the connection deadline if
# the read is still waiting and nothing else on the connection is still within its own
# deadline -- a backstop against an adapter that holds the read again, and a bound a host
# can set below the read deadline. Armed only over HTTP/2; over HTTP/1 the loop below
# bounds every read.
watchdog = arm_connection_watchdog(conn, connection_timeout)

try do
Expand Down Expand Up @@ -813,7 +813,7 @@ if Code.ensure_loaded?(Plug) do
# stream records its own connection deadline in its process dictionary and spawns a
# watchdog that closes the whole connection at the connection deadline IF the read is
# still blocked and no other stream on the connection is still within its own deadline.
# Over HTTP/1 there is no residue -- the loop bounds every read -- so nothing is armed.
# Over HTTP/1 the loop bounds every read, so nothing is armed.
defp arm_connection_watchdog(conn, connection_timeout) do
if http_protocol(conn) == :"HTTP/2" and is_integer(connection_timeout) do
arm_watchdog_on(connection_pid(), connection_timeout)
Expand Down Expand Up @@ -939,25 +939,19 @@ if Code.ensure_loaded?(Plug) do
# remains". A body at the cap is then refused by the size rule on the next frame, or
# accepted when the stream ends.
#
# What this cannot reach: a frame that carries no DATA. A WINDOW_UPDATE re-arms the
# adapter's own wait for the whole of what this call gave it -- one such frame per
# deadline holds the stream indefinitely -- and that wait is a
# receive on the adapter's messages that nothing outside it can end through an interface
# the adapter offers. Two levers exist and both are declined: forging the adapter's own
# What this cannot reach: a frame that carries no DATA. Its effect on the read is the
# adapter's, inside a receive that nothing outside it can end through an interface the
# adapter offers. Two levers exist and both are declined: forging the adapter's own
# message into the stream process's mailbox couples this package to a private protocol
# that a release of the adapter can change silently; ending the stream process gives the
# client no answer at all (the adapter forgets the stream and drops its frames). So a
# stream kept open by control frames alone is held by the adapter past the deadline, and
# whatever body comes is refused here, since the clock is read on return. A WINDOW_UPDATE
# is thirteen bytes and nothing accumulates. (A HEADERS without END_STREAM -- a malformed
# request under RFC 9113, 8.1 -- was the second such frame until `Bandit` 1.13, which now
# raises a stream error for it; `adapter/1` hands that back to the adapter, which resets
# the stream.) The host's cost is one stream process held for as long as the frames
# keep coming, up to the adapter's streams-per-connection setting -- but bounded in
# DURATION by the connection watchdog above: the stream itself cannot be ended from
# outside the adapter, so at the connection deadline the whole connection is closed with
# a GOAWAY. The threat model states the residue as the adapter's, with tests that fail
# the day the adapter honours the deadline it is given.
# client no answer at all (the adapter forgets the stream and drops its frames). Before
# `Bandit` 1.14 a WINDOW_UPDATE re-armed the adapter's wait for the whole of what this call
# gave it, so one such frame per deadline held the stream indefinitely (and a HEADERS
# without END_STREAM did the same until 1.13, which now raises a stream error for it that
# `adapter/1` hands back). 1.14 bounds the read by the timeout given (GHSA-p2qv-vx88-385x),
# and on 1.15, this package's floor, WINDOW_UPDATE, PING, SETTINGS and PRIORITY frames were
# each measured answered at the deadline; tests pin each, so an adapter release that holds
# the read again fails the gate. The connection watchdog above stays as the backstop.
defp piece_length(true, size), do: min(@read_piece, @max_body_bytes - size)
defp piece_length(false, _size), do: -1

Expand Down
16 changes: 11 additions & 5 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,17 @@ defmodule BeamMCP.MixProject do
# optional: a host using only the stdio transport must not be made to pull an HTTP
# server in, and `optional: true` keeps them out of that host's dependency tree.
{:plug, "~> 1.16", optional: true},
# 1.13 is a security floor, not a feature one: below it Bandit carries EEF-CVE-2026-105659
# (HTTP/2 send deadlines reset by every WINDOW_UPDATE) and EEF-CVE-2026-105660 (an HTTP/1
# request target choosing conn.host and conn.port). A host that pulls Bandit in beside this
# transport resolves to a fixed one; a host that does not is unaffected (optional).
{:bandit, "~> 1.13", optional: true},
# 1.15 is a security floor, not a feature one. Below 1.13 Bandit carries
# EEF-CVE-2026-105659 and -105660; below 1.14.0, twelve more advisories published
# 2026-10-26 (HTTP/2 flow control, stream count, HPACK and SETTINGS work, 1-byte chunked
# and WebSocket frames, chunk extensions that smuggle, bignum Content-Length, the body read
# timeout reset by control frames); below 1.14.1, GHSA-pxjf-g536-7r93 (1-byte HTTP/2 DATA
# frames); below 1.15.0, GHSA-j9wq-h5xx-5qx5 (logging HTTP/2 trailers). This transport
# serves HTTP/2 by default, so each reaches a host that serves it. A host that pulls Bandit
# in beside this transport resolves to a fixed one; a host that does not is unaffected
# (optional). Plug's EEF-CVE-2026-120287 is in Plug.Parsers.MULTIPART, which this package
# never calls, so Plug's floor stays and only the lock moves.
{:bandit, "~> 1.15", optional: true},
{:credo, "~> 1.7", only: [:dev, :test], runtime: false},
{:ex_doc, "~> 0.31", only: :dev, runtime: false},
# Property tests. Test-time only; it does not enter the published package.
Expand Down
Loading