Repository navigation
Description
Summary
Protocol/gossip robustness and DoS hardening surfaced by a code review. Four related issues in the wire-protocol and gossip layers, grouped because they share the same theme (bounding adversary-controlled input/state on the unauthenticated network surface).
H3 — PeerTable has no entry cap → memory-DoS via empty-allowlist PoC default
crates/gossip/src/peer_table.rs:44-109 — insert_or_refresh inserts unboundedly. With an empty allowlist (crates/gossip/src/validation.rs:84-86, the documented PoC stand-in for the on-chain stake check), any peer can mint unlimited fresh ed25519 keypairs and emit one signature-valid NodeAnnounce each. The only bound is the 30s TTL sweeper (service.rs:430-446); within one peer_ttl_sec window (default 600s) millions of entries can be inserted. Signature verification is the only (cheap) cost gate. Note cache's evicted-set has an explicit MAX_EVICTED_ENTRIES cap — the peer table is the inconsistent one.
Fix: add a max_entries cap mirroring MAX_EVICTED_ENTRIES. On overflow reject new node IDs (still allow refresh of existing), bump a rejection metric, or evict oldest last_seen_us; trigger a sweep on insert above a soft threshold.
H2 — Gossip subscriber discards the reconnected topic's GossipSender
crates/gossip/src/service.rs:334-340 — on reconnect, let (_sender, new_receiver) = topic.split(); discards the fresh sender. The publisher task (publisher_task, line 412) keeps broadcasting through the original senders captured at spawn. After a topic stream reset + re-subscribe, the two halves recover independently and can desynchronize, so manual/interval announces may silently stop landing. No test exercises publish-after-subscriber-reconnect.
Fix: make resubscription own both halves, or publish the new sender back to the publisher (e.g. ArcSwap/watch channel). Add a post-reconnect publish test.
M3 — Unbounded trailing-byte padding within the 16 MiB frame cap
crates/protocol/src/framing.rs:60-64, crates/gossip/src/validation.rs:104-106 — take_from_bytes tolerates a trailing remainder (correct for ADR 013 Tier-1 forward-compat) but it is unbounded within the 16 MiB frame cap. A peer can pad every NodeAnnounce with ~16 MiB of ignored bytes; read_frame allocates len before decode, forcing a 16 MiB allocation per ~150-byte announce, multiplied by gossip fan-out.
Fix: reject/cap when _rest.len() exceeds a small allowance (a few KiB) in the gossip validation path, or enforce a tighter per-ALPN frame ceiling for gossip than the global 16 MiB. Add an AnnounceReject variant + label for oversize trailing bytes.
M1 — Probe handler maps transport I/O errors to MALFORMED_MESSAGE
crates/node/src/handlers/probe.rs:172-180 (with crates/protocol/src/framing.rs:44-53) — FrameError::Io(_) (short read / peer reset / mid-frame EOF) is collapsed into APP_ERR_MALFORMED_MESSAGE (0x03) alongside genuine Varint/Decode faults. A truncated frame from a transport drop is not a protocol fault; mislabeling it may cause peers to apply the wrong backoff/penalty.
Fix: map FrameError::Io(_) to "no app error" (code 0, as the read-timeout path already does at probe.rs:209-221) or a distinct transport code; keep MALFORMED_MESSAGE for Varint/Decode. Add a test asserting an I/O-truncated frame does not surface 0x03.
Filed from a repository review.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
fix(gossip): throttle PeerTable inline TTL sweep to ≤1/sec (#577 H3 r…
refactor(gossip): TopicWiring struct + resubscribe metric + tighten t…
fix(gossip): swap publisher's sender on subscriber reconnect (#577 H2) (
docs(adr): ADR 013 §Application Error Codes — Io→0x00, not 0x03 (#577 …
refactor(gossip): forensic log + ordering test + doc tightenings (#577 …
fix(577): trailing-byte padding cap (M3) + probe I/O classification (…