Unbounded request body accumulation on streaming RPCs causes memory exhaustion in grpc_server
Description
grpc_server does not enforce its configured max_body_size on request-streaming or bidirectional-streaming gRPC calls. An unauthenticated remote client can open any streaming RPC method and send an unbounded amount of data across many small HTTP/2 DATA frames, causing the server to buffer all of it in memory and eventually exhaust the BEAM's memory and crash the node.
Details
GRPC.Server.Adapters.Cowboy.Handler enforces max_body_size on single-request/single-response calls but not on the streaming read path, which buffers every inbound chunk with no upper bound. The commit that introduced max_body_size applied the check only to non-streaming requests, so any service exposing a streaming RPC method inherited an unbounded-buffering path even though non-streaming calls on the same server are protected.
PoC
- Start a
grpcserver exposing any request-streaming or bidirectional-streaming RPC (a client-streaming method is sufficient). - Open an HTTP/2 connection and send a request to that streaming method.
- Send the request body across many small HTTP/2 DATA frames without the final
END_STREAMflag, continuing well past the server's configuredmax_body_size. - Observe the server accepts and buffers all of it, memory growing without bound, instead of rejecting the call once the cap is exceeded (as the equivalent non-streaming call does).
Impact
An unauthenticated attacker can crash a grpc_server-based service by exhausting its memory through a single streaming RPC connection, so long as the target exposes at least one streaming RPC method; services with only single-request/single-response calls are not reachable this way.