Skip to content

fix(rpc): stop reading the HTTP body at the configured cap - #33

Open
MeABzZz wants to merge 2 commits into
BTCDecoded:mainfrom
MeABzZz:maya/rpc-body-auth-guard
Open

MeABzZz wants to merge 2 commits into
BTCDecoded:mainfrom
MeABzZz:maya/rpc-body-auth-guard

Conversation

@MeABzZz

@MeABzZz MeABzZz commented Oct 21, 2026 •

Copy link
Copy Markdown

What remains after main

Josh's a694465 ("cap RPC bodies…") already moved the HTTP/1 JSON-RPC read onto http_body_util::Limited, so an unauthenticated client can no longer make the node buffer an unbounded body. This PR is now rebased onto that change with a merge commit, and only the remaining delta is left:

  • main caps the read at the compile-time DEFAULT_MAX_REQUEST_SIZE (1 MiB), so a configured max_request_size above 1 MiB can never be used. Any larger body gets a 413 before the configured check runs.
  • this PR changes one line, Limited::new(req.into_body(), server.max_request_size), so the server stops reading at the configured cap, whether that is smaller or larger than 1 MiB.

Diff vs main: src/rpc/server.rs, the one-line cap change plus two tests.

Verification (Rust 1.88.0, branch head 8641580, includes node main 4f1be96)

test main's line (mutation) this branch
http1_accepts_body_under_a_cap_above_the_default (2 MiB cap, ~1.5 MiB body) FAILED: 413 Payload Too Large ok, 200
http1_rejects_oversized_body_before_the_remainder_is_sent FAILED: Elapsed (waits for the rest of the body) ok
  • Also passing on the branch: lib rpc:: 161, rpc_tests 29, rpc_edge_cases 9, rpc_advanced_scenarios 9.
  • Full cargo test --no-fail-fast: 3016 passed / 2 failed / 26 ignored (main 4f1be96: 3016 / 0 / 26). Both failures are in modules this PR doesn't touch (storage::ibd_engine::disk_index::…async_spill_serves_queries_via_pending_then_registers, node::parallel_ibd::chunk_assigner::…a6m_gd_slow_open_uncools_prior_hero_when_pin_empty). Rerun on this branch, they passed 5 out of 5 times, so they are timing-dependent under the full parallel run. The other three reconciled branches had 0 failures.
  • cargo clippy --all-targets: the same 90 diagnostics as main, with 0 new. Main already fails lib-test clippy on two nonminimal_bool errors in src/node/parallel_ibd/chunk_assigner_tests.rs (5044, 5105), which this PR doesn't touch.
  • rustfmt --check on src/rpc/server.rs: clean. Note that main itself isn't cargo fmt --check clean (tests/feature_flags_reflection_tests.rs:7, already there on 4f1be96).

Review notes

MeABzZz and others added 2 commits October 21, 2026 15:07
HTTP/1 JSON-RPC collected the entire POST body before checking the
1 MiB limit and before authentication. Read through http_body_util::Limited
so the request is refused with 413 as soon as the cap is crossed.

The public-bind auth guard from the original branch (RPC and REST) is
already on main via 8fcda11 and is not repeated here.

Re-applied on main d9c9b37 from cursor/rpc-body-auth-guard-7567 (original branch left as-is).

Co-authored-by: joshswift <joshswift@protonmail.com>
Keep main's streaming Limited body read (a694465) and change only its cap
from the fixed DEFAULT_MAX_REQUEST_SIZE to the configured
max_request_size. Add a test that a configured cap above 1 MiB is usable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant