Skip to content

Limit electrum rpc request line length - #257

Merged
agoodminute merged 1 commit into
Blockstream:new-indexfrom
agoodminute:fix/limit-request-length
Sep 8, 2026
Merged

Limit electrum rpc request line length#257
agoodminute merged 1 commit into
Blockstream:new-indexfrom
agoodminute:fix/limit-request-length

Conversation

@agoodminute

Copy link
Copy Markdown
Collaborator

Summary

Connection::parse_requests read each incoming Electrum RPC request as a single line via read_until(b'\n', ...), with no limit on how large that line could grow before a newline arrived. This adds a bounded line reader and a configurable cap on request size.

Why

A request line with no upper bound means a single slow or unusually large request could grow the read buffer without limit before being rejected or completed. Capping the size up front keeps per-connection memory usage predictable regardless of what a client sends.

Changes

  • New Connection::read_bounded_line — reads a \n-terminated request line, checking the accumulated size against the configured limit before extending the buffer, rather than only after the read completes.
  • New config option --electrum-rpc-max-request-num-bytes (electrum_rpc_max_request_num_bytes), default 1 MiB. A request line exceeding the limit is rejected and the connection is dropped. 0 disables the limit.
  • parse_requests / reader_thread now thread this limit through to the bounded reader instead of reading unbounded lines.

- limit electrum rpc requests to 1 MiB default
- provide option to increase limit

@EddieHouston EddieHouston left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm 82ef302

@agoodminute
agoodminute merged commit d9264a0 into Blockstream:new-index Sep 8, 2026
6 checks passed
@agoodminute
agoodminute deleted the fix/limit-request-length branch September 8, 2026 11:22
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.

4 participants