fix(p2p): require auth on /p2p/gossip POST + correct state root endianness - #8198
Open
rebel117 wants to merge 1 commit into
Open
fix(p2p): require auth on /p2p/gossip POST + correct state root endianness#8198rebel117 wants to merge 1 commit into
rebel117 wants to merge 1 commit into
Conversation
The /p2p/gossip POST endpoint — the write path that feeds CRDT merges and can inject attestation records or epoch state — had no auth gate, while every P2P GET endpoint required X-P2P-Key. Added the same _require_p2p_read_auth() check to the gossip handler so unauthenticated callers can't write to the CRDT. Also fixed the state root merkle tree count prefix from little-endian to big-endian to match the convention used by compute_box_id and the rest of the UTXO hashing code.
Contributor
|
Welcome to RustChain! Thanks for your first pull request. Before we review, please make sure:
Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150) A maintainer will review your PR soon. Thanks for contributing! |
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
Fixes #8177 — two findings addressed.
Finding 1: /p2p/gossip POST has no auth
Every P2P read endpoint (
/p2p/state,/p2p/attestation_state,/p2p/peers) calls_require_p2p_read_auth()to validate theX-P2P-Keyheader. The gossip POST — the write endpoint that feeds CRDT merges viap2p_node.handle_gossip()— had only per-IP rate limiting, no auth.That meant any network-accessible attacker could POST gossip messages without knowing the P2P secret, potentially injecting fake attestation records or corrupting epoch state.
Fix: Added
_require_p2p_read_auth()at the top of thereceive_gossiphandler, before the rate limit check.Finding 2: State root endianness mismatch
compute_box_id()usesto_bytes(8, "big")andto_bytes(2, "big")for all integer encoding. The state root merkle tree leaf computation usedlen(rows).to_bytes(8, "little")for the count prefix — inconsistent with the rest of the hashing code.Fix: Changed to
to_bytes(8, "big")so the state root is deterministically reproducible across implementations assuming uniform big-endian encoding.Testing
test_p2p_gossip_requires_auth_header(verifies 401 without key) andtest_p2p_gossip_accepts_valid_auth(verifies 200 with valid key)X-P2P-Keyheaderpytest node/tests/test_p2p_gossip_routes.py— 6/6 pass