Repository navigation
fix(blocksync): validate peer block and status responses - #1355
Conversation
Order the nil checks in BlockResponse.Validate before any field access, reject a fetched block whose height does not match the requested height, and bound peer-reported StatusResponse base/height to plausible values (implausible reports are logged and ignored without dropping the peer). Adds table-driven tests for nil-block rejection, out-of-range status reports, and block height-mismatch rejection. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
✅ Review complete (commit 749fab6) |
|
Caution Review failedAn error occurred during the review process. Please try again later. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
Focused, well-scoped hardening of the blocksync receive path: nil-Block guard in BlockResponse.Validate, requested-height match in the fetch job, and base/height plausibility on StatusResponse. The changes are correctly wired (errBlockFetch propagates to pushBack/RemovePeer/PeerError) and have matching tests. No blocking issues. One stylistic nitpick on log severity for peer-controlled input.
💬 1 nitpick(s)
There was a problem hiding this comment.
Pull request overview
This PR hardens the block-sync pipeline against malformed or malicious responses from unauthenticated P2P peers, focusing on avoiding nil dereferences and rejecting implausible or inconsistent peer-reported data.
Changes:
- Strengthened
BlockResponse.Validate()to reject nil blocks/commits and enforce block/commit height consistency. - Added defensive validation around
StatusResponse(reject negative/illogical heights and cap overly large heights to avoid overflow in downstream arithmetic). - Ensured fetched blocks match the requested height, with new unit tests covering these cases.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/blocksync/synchronizer.go | Tightens BlockResponse.Validate() with explicit nil checks and strict height matching. |
| internal/blocksync/p2p_msg_handler.go | Adds plausibility bounds for peer-reported status heights to prevent overflow/invalid ranges. |
| internal/blocksync/p2p_msg_handler_test.go | Expands status-response test coverage for valid and invalid peer status values. |
| internal/blocksync/block_fetch_job.go | Rejects peers that return a block at a height different from the requested height. |
| internal/blocksync/block_fetch_job_test.go | Adds tests for height mismatch handling and BlockResponse.Validate() behavior. |
Summary
Hardens the block-sync path against malformed responses from unauthenticated P2P peers.
Changes
BlockResponse.Validate.StatusResponseBase/Height (log + ignore implausible values).🤖 Generated with Claude Code