Limit electrum rpc request line length - #257
Merged
agoodminute merged 1 commit intoSep 8, 2026
Merged
Conversation
- limit electrum rpc requests to 1 MiB default - provide option to increase limit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Connection::parse_requestsread each incoming Electrum RPC request as a single line viaread_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
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.--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.0disables the limit.parse_requests/reader_threadnow thread this limit through to the bounded reader instead of reading unbounded lines.