Skip to content

[Hardening] Validate legacy block_headers length before slicing (F-007) #236

Open

Description

@kaslovdmitri

Summary

In rust-electrum-client 0.25.2 (reported upstream commit 7c1d759), the pre-1.6 legacy response path for blockchain.block.headers trusts the server-controlled result.count and slices the decoded header bytes in fixed 80-byte chunks without validating the available length. A malicious or compromised Electrum server (or an attacker able to alter the Electrum connection) can make a release build panic, causing client/wallet availability loss.

Reproduction

  1. Build the client in release mode.
  2. Connect to a mock TCP Electrum server.
  3. Negotiate protocol version 1.4.
  4. Return this response to blockchain.block.headers:
{"jsonrpc":"2.0","id":1,"result":{"count":1,"max":8,"hex":""}}

Observed:

range end index 80 out of range for slice of length 0

A negative control containing one valid 80-byte header with count=1 returns normally. A count=3 response containing only one header panics at the second slice.

Source

Reported source location: raw_client.rs lines 1062–1068 (in the affected revision).

Suggested hardening

  • Validate the decoded header byte length (and its consistency with count) before fixed-size slicing.
  • Return a normal protocol error on mismatch instead of panicking.
  • Add regression tests for empty/truncated headers and mismatched counts.

This is a hardening issue: the demonstrated impact is availability loss in release mode; no fund or privacy compromise was observed.

Activity

  1. self-assigned this
    on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions