Remote process crash (OOM) via post‑serialization size check and large batch aggregation in JSON‑RPC
The JSON-RPC server builds and serialises the whole response, including entire batches, in memory before checking the response size cap, and it allows very large batches by default. An unauthenticated client could send a crafted request or batch that makes the process allocate many gigabytes and be killed by the OOM killer, denying service to honest users.
RadiantLabs Follow with Almanax and johnyfwesh
Originally disclosed on Code4rena
Submitted by RadiantLabs, also found by Almanax and johnyfwesh
bft/monad-rpc/src/handlers/mod.rs#L129-L151bft/monad-rpc/src/handlers/mod.rs#L154-L169bft/monad-rpc/src/handlers/eth/txn.rs#L154-L181bft/monad-rpc/src/handlers/eth/gas.rs#L402-L466bft/monad-rpc/src/cli.rs#L63-L73
The JSON‑RPC server fully materializes and serializes responses before enforcing the response size cap, and it aggregates entire batches into memory before a final serialization pass. This creates a multiplicative memory footprint that an unauthenticated client can exploit to exhaust memory and crash the process under default settings.
- Batch aggregation:
rpc_handler()runs each request concurrently viafutures::future::join_all(...), collects(id, Result<Box<RawValue>, JsonRpcError>)pairs, and converts them into aVec<Response>. EachResponsealready contains a pre-serializedBox<RawValue>for the per‑item result. - Post‑serialization size check: After the batch is fully constructed, the server calls
serde_json::value::to_raw_value(&response)to serialize the entireResponseWrapperinto a second largeRawValue, and only then checks its size: seeresponse_raw_valueand the subsequent length check inrpc_handler(). This duplicates memory usage at the worst possible time (the entire batch), so the size cap rejects only after the peak allocation. - Amplification surface:
eth_getLogsproduces large outputs and lacks per‑endpoint concurrency gating. The RPC wrapper simply fetches and returnsVec<MonadLog>inmonad_eth_getLogs(). Whileeth_call/eth_estimateGashave a permit‑based limiter, there is no equivalent guard foreth_getLogsin theeth_getLogswrapper. - Defaults exacerbate the issue: the CLI defaults permit very large batches and a relatively high response size cap (
batch_request_limit = 5000,max_response_size = 25_000_000) inCli. With N=5000 and per‑item results of even ~200 KB, the batch holds ~1 GB of per‑itemRawValuebuffers before creating the final batchRawValue. With ~1.5 MB per item (wideeth_getLogsfilters), this easily reaches many GB, resulting in OOM or severe swapping/CPU thrash before the size cap is applied.
The same late size check also applies to ResponseWrapper::Single. Combined with costly response builders like monad_eth_feeHistory(), a single request can allocate very large structures (e.g., reward matrices sized by block_count × len(reward_percentiles)) and only then be rejected after serialization.
Worst‑case outcome: A single crafted request or one batch forces the server to build large in‑memory results and then serialize the entire wrapper. Memory balloons and the process is terminated by the OOM killer or becomes unresponsive, denying service to honest users. This is an implementation‑specific weakness, not a generic network flood, and is exploitable on default config.
Recommended mitigation steps
Option A (preferred): stream responses with budgeting
- Replace final
serde_json::value::to_raw_value(&response)with a streaming JSON encoder forResponseWrapperthat writes to the HTTP body while tracking a byte budget. - Abort emission early with an error once the per‑request or aggregate batch budget is exceeded.
- This avoids constructing a second massive
RawValue.
Option B (quick hardening/defense in depth): cap batch and pre‑reject oversized batches
View detailed Proof of Concept
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the response size limit is enforced only after the full response or batch has been serialised into memory, and large batches are permitted by default, so peak memory use is not bounded.
Impact
A single crafted request or batch could exhaust memory and cause the process to be terminated or become unresponsive, denying service to honest users; the text notes this is exploitable on default config.
What the attacker needed
No authentication needed; default server configuration
The fix
It should be fixed by streaming responses with a byte budget that aborts early, and by capping or pre-rejecting oversized batches.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A JSON-RPC server answers requests from programs, and it can handle many requests bundled together as a batch. This server builds every answer in memory first and only afterwards checks whether the answer is too big, so a large batch can use a huge amount of memory before any limit applies. If memory runs out, the operating system kills the process and the service stops working for everyone.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.