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

未关闭 适合新手
#236 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@notmandatory 已经在做这个了。

开始于 2026年11月9日。

  • #238 来自 @notmandatory —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
rust

调研方向

从受影响版本中 raw_client.rs 第1062–1068行开始,追踪协议1.4的旧版 blockchain.block.headers 响应处理。检查解码后的头部长度和 count 在切片前如何使用,然后为头部为空、被截断以及数量不匹配的情况添加回归测试。完成标准是:格式错误的响应返回协议错误且不会触发 panic,同时有效的头部响应仍能正常工作。

由索引模型根据 Issue 内容生成。

描述

bug

Summary

In rust-electrum-client 0.25.2 (reported upstream commit 7c1d759e2789b5e46fcae1525ab06ff4012bc668), 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.

主要语言
Rust
星标
89
派生
87
平均合并
1 小时 25 分钟
30 天内合并 PR
4

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

bitcoindevkit/rust-electrum-client 的其他 Issue

查看 bitcoindevkit/rust-electrum-client 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。