[Hardening] Reject non-object JSON notifications without panicking (F-008)

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

@notmandatory 已经在做这个了。

开始于 2026年11月9日。

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

评估

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

调研方向

从 raw_client.rs 第764–773行附近开始,这里是通知路径读取 JSON 响应字段的位置。检查非对象 JSON 值的处理方式,然后为标量、数组和 null 通知添加回归测试。完成标准是:无效的通知形状会返回正常的协议错误或解析错误,而不会 panic;同时,null 负对照仍允许 ping 完成。

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

描述

bug

Summary

In rust-electrum-client 0.25.2 (reported upstream commit 7c1d759e2789b5e46fcae1525ab06ff4012bc668), the reader notification path accesses resp["method"].take(). A server-pushed JSON scalar without an id is treated as a notification, but mutable indexing a scalar JSON value panics. A malicious or compromised Electrum server (or an attacker able to alter the Electrum connection) can therefore cause client/wallet availability loss in a release build.

Reproduction

  1. Build the client in release mode.
  2. Negotiate protocol version 1.4.
  3. While a request is in flight, send this line:
5

Observed:

serde_json panic: cannot access key "method" in JSON number

A null notification was tested as a negative control and the subsequent ping completed normally.

Source

Reported source location: raw_client.rs lines 764–773 (in the affected revision).

Suggested hardening

  • Require a JSON object before reading notification fields, or use non-panicking accessors such as get("method").
  • Return a normal protocol/parse error for invalid notification shapes.
  • Add regression tests for scalar, array, and null notifications.

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 摘要。