Repository navigation
fix(577): trailing-byte padding cap (M3) + probe I/O classification (M1) - #659
Conversation
ADR 013 §Tier 1 permits trailing bytes after the postcard envelope for forward-compat, and `validate_envelope` correctly used `take_from_bytes` to ignore them — but the remainder was unbounded. A peer could pad every ~150-byte `NodeAnnounce` up to iroh-gossip's per-message ceiling (~16 MiB), forcing a 16 MiB allocation per signature-valid announce across the gossip fan-out. Add `MAX_TRAILING_BYTES = 4 KiB` and reject anything above it with a new `AnnounceReject::OversizeTrailingBytes` variant + `oversize_trailing_bytes` metric label (pinned in the existing label-stability test). The check runs before signature verification so an attacker can't burn ed25519 cycles on a shape we'll drop regardless. This is detection-only: iroh-gossip has already allocated the padded message by the time `validate_envelope` runs. Tightening the upstream allocation requires a size knob on `gossip.subscribe(...)` which iroh-gossip 0.98 doesn't expose; that fix is tracked as a follow-up. The cap here surfaces the attack via metric and keeps the polluted announce out of the peer table. Boundary pair (`rejects_oversize_trailing_bytes` / `accepts_trailing_bytes_at_threshold`) mirrors the existing `evict_at_exact_cutoff` / `one_microsecond_past_cutoff` discipline so a regression that flipped `>` to `>=` is caught. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…M1)
`frame_err_code` in the probe handler collapsed `FrameError::Io(_)`
(transport-level short read, peer reset, mid-frame EOF) into
`APP_ERR_MALFORMED_MESSAGE` (0x03) alongside the genuine `Varint` and
`Decode` faults. A truncated frame from a transport drop is not a
protocol fault; collapsing the two would push peers toward the wrong
backoff/penalty discipline. The existing read-timeout path already
maps to code 0 ("no app error") with an ADR-013 comment — the same
convention now applies here.
Split `FrameError::Io(_)` into its own arm returning the newly-named
`APP_ERR_NO_ERROR` (0x00). The constant makes the QUIC implicit-default
explicit; the timeout path now references it too so the two transport-
fault sites share one named value rather than a magic literal.
New `probe_io_truncated_frame_returns_zero_code` integration test
exercises the path end-to-end: client writes a valid varint length
prefix promising 100 bytes, then writes 3 bytes and finishes the
stream → `read_frame` short-reads → `FrameError::Io(UnexpectedEof)`
→ server closes with 0x00, not 0x03. Pairs the existing
`probe_garbage_postcard_returns_malformed_code` (genuine `Decode`
fault, 0x03) and `probe_read_timeout_resets_stream_with_zero_code`
(timeout, 0x00).
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR closes the remaining M3/M1 items from #577 by tightening gossip envelope validation against padded trailing bytes and improving probe handler error-code classification for transport I/O failures.
Changes:
- Add a 4 KiB cap on tolerated trailing bytes after a postcard
GossipEnvelope, with a newAnnounceReject::OversizeTrailingBytesreject reason + stable metric label, and boundary tests. - Update probe handler to map
FrameError::Io(_)toAPP_ERR_NO_ERROR (0x00)(separating transport drops from protocol faults), and add an integration test covering truncated frames.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/gossip/src/validation.rs | Add MAX_TRAILING_BYTES cap + new rejection variant/label; enforce cap before signature verification; add boundary tests. |
| crates/node/src/handlers/probe.rs | Introduce APP_ERR_NO_ERROR constant; map FrameError::Io(_) to 0x00; reuse constant in timeout path. |
| crates/node/tests/probe_loopback.rs | Add integration test asserting truncated-frame I/O errors return app code 0x00. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 90.04% (was 90.04%, ● 0.00%) — 17072/18960 lines
History
|
There was a problem hiding this comment.
Code Review
This pull request implements a 4 KiB limit on trailing bytes in gossip envelopes to mitigate potential resource exhaustion attacks and refines error handling in the probe handler. Transport-level IO errors and timeouts now return a 'no error' QUIC code (0x00) to distinguish them from protocol-level malformed message errors. Comprehensive tests were added to validate the new trailing byte limits and the updated error code mappings. I have no feedback to provide as no review comments were submitted.
…M1) PR #659 changed the probe handler to map `FrameError::Io(_)` to `APP_ERR_NO_ERROR (0x00)` instead of `APP_ERR_MALFORMED_MESSAGE (0x03)`. ADR 013's table normatively said the opposite — Copilot review on #659 caught the drift. Updates the two affected rows: - `0x00 NO_ERROR` — now explicitly lists transport-level conditions (read timeout, short read, peer reset, mid-frame EOF) and adds the MUST NOT clause: peers observing 0x00 after a partial exchange must not apply the protocol-fault backoff associated with 0x03. - `0x03 MALFORMED_MESSAGE` — narrows to application-layer decoding failures (postcard, varint). The original parenthetical ("the receiver cannot distinguish a truncated frame from a malformed one at the application layer") was correct only for a framing API that collapsed Io and Varint/Decode into one variant; `FrameError` has always kept them separate, so the distinction is available and the ADR should reflect it. No other ADR references contradict the new mapping (ADR 022's MALFORMED_MESSAGE references are for batch-size violations — genuine protocol faults — and are unaffected). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…M3 review) Follow-up on PR #659 review (silent-failure + pr-test-analyzer + comment-analyzer + type-design): - Add `tracing::warn!` at the service-layer caller for the `OversizeTrailingBytes` rejection variant only (#577 M3). Counter- only observability was thin for what the variant doc-comment explicitly frames as an active-attack signal; the warn surfaces topic + content_len + max_trailing so operators investigating a metric spike have correlation context without enabling debug logging. Gated to this single variant so the routine per-peer rejection paths (BadRegion, ClockSkew, etc.) stay log-quiet — they are not attacker-controlled signals worth flooding the log for. Implemented at the call site, not inside `validate_envelope`, to preserve the "Pure, no-IO validation" contract documented at the top of validation.rs. - Add `rejects_oversize_before_checking_signature` test. The variant's doc-comment promises "reject before signature verify so an attacker can't burn ed25519 cycles", but the existing `rejects_oversize_trailing_bytes` test couldn't catch a regression that swapped the order (its envelope's signature is valid). The new test corrupts the signature *and* over-pads — must surface `OversizeTrailingBytes`, not `InvalidSignature`. - Tighten `MAX_TRAILING_BYTES` doc: replace the inaccurate "iroh-gossip's 16 MiB ceiling" wording with a direct cite of deCDN's `MAX_MESSAGE_SIZE` constant (ADR 013 §Wire Framing) plus an inline quote of the operator-policy note so the cross-reference is self-contained. - Use full test names (`evict_at_exact_cutoff_keeps_entry` / `evict_one_microsecond_past_cutoff_removes_entry`) in `accepts_trailing_bytes_at_threshold` docstring so grep-on-rename finds the linked tests. - Soften the ADR 013 `0x00 NO_ERROR` MUST NOT clause: note explicitly that enforcement lives on the reputation/backoff layer (ADR 008 §Local Score Calculation, yet to be built) so future readers don't treat it as binding contract today. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…#661) * fix(gossip): pin iroh-gossip frame ceiling to GOSSIP_MAX_FRAME (#660) Wires iroh-gossip's per-actor `max_message_size` to a deCDN-controlled `GOSSIP_MAX_FRAME = 16 KiB` (ADR 013 §Gossip Framing) via a new `decdn_gossip::build_gossip` helper used by both the runtime and the regression test. Replaces the silent reliance on iroh-gossip 0.98's 4 KiB default — too tight to carry our `MAX_TRAILING_BYTES` extension allowance — and corrects PR #659's stale doc-comments that conflated deCDN's `MAX_MESSAGE_SIZE` (probe/client ALPNs) with iroh-gossip's unrelated per-actor cap. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(gossip): use American spelling and single backticks in doc-comments Address PR #661 review comments: switch "defence-in-depth" to "defense-in-depth" (matches the 10 existing files using American spelling, e.g. adr/001-network.md) and fix accidental double backticks around `HyParView` in the network-coordination invariant paragraph. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * fix(gossip): correct HyParView topic-scoping claim and amplification framing Comment fixes surfaced by the post-fix re-review: - HyParView control frames ARE topic-scoped — every iroh-gossip wire frame carries a TopicId (`iroh_gossip::proto::state::Message<PI>`), and iroh-gossip maintains a separate HyParView swarm per topic. The prior parenthetical "(which are not topic-scoped)" was the inverse of reality. Rephrased to convey the intended point (tightening GOSSIP_MAX_FRAME breaks legitimate non-payload frames too). - "~100× across the gossip fan-out" conflated per-frame size ratio (16 KiB / 150 B ≈ 109×) with Plumtree fan-out (eager-peer count). Reworded to name them as separate multipliers. - `AnnounceReject::OversizeTrailingBytes` doc-comment now states the 4 KiB threshold inline so operators reading the metric label don't have to chase `MAX_TRAILING_BYTES`. - `build_gossip` doc-comment now pins the 4 KiB upstream default to iroh-gossip 0.98 so a future minor-version bump that shifts it doesn't silently invalidate the comment. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Closes the two remaining items from #577 (H2/H3 already shipped via #656 and #657).
M3 —
crates/gossip/src/validation.rsvalidate_envelopeusedtake_from_bytesto permit ADR-013 §Tier-1 trailing bytes for forward-compat, but the remainder was unbounded. A peer could pad every ~150-byteNodeAnnounceup to iroh-gossip's per-message ceiling (~16 MiB), forcing a 16 MiB allocation per signature-valid announce across the gossip fan-out.MAX_TRAILING_BYTES = 4 KiB+AnnounceReject::OversizeTrailingBytes+oversize_trailing_byteslabel (pinned inreject_labels_are_stable).rejects_oversize_trailing_bytes+accepts_trailing_bytes_at_threshold) catches a>/>=flip.Detection-only: iroh-gossip has already allocated the padded message by the time
validate_enveloperuns. Tightening the upstream allocation needs a size knob ongossip.subscribe(...)which iroh-gossip 0.98 doesn't expose — I'll file that as a follow-up tracking issue after this merges. The cap here surfaces the attack via metric and keeps the polluted announce out of the peer table.M1 —
crates/node/src/handlers/probe.rsframe_err_codecollapsedFrameError::Io(_)(transport-level: short read, peer reset, mid-frame EOF) intoAPP_ERR_MALFORMED_MESSAGE(0x03) alongside genuine protocol faults. A transport drop is not a protocol fault; mislabeling would push peers toward the wrong backoff/penalty discipline.APP_ERR_NO_ERROR = 0x00. SplitFrameError::Io(_)into its own arm returning that code.0to use the new const for consistency.probe_io_truncated_frame_returns_zero_codeintegration test: client promises 100 bytes via varint, writes 3, finishes → server closes with 0x00, not 0x03. Pairs the existingprobe_garbage_postcard_returns_malformed_code(0x03) andprobe_read_timeout_resets_stream_with_zero_code(0x00) tests.Test plan
cargo nextest run -p decdn-gossip— 39/39 (2 new M3 boundary tests).cargo nextest run -p decdn-node --test probe_loopback— passes new truncation test + all existing close-code tests.cargo nextest run --workspace— 934/934.cargo clippy --workspace --all-targets -- -D warnings— clean.cargo fmt --check+pre-commit run— clean.Out of scope (follow-up tracking)
A deeper M3 fix would set a tighter per-ALPN frame ceiling on the gossip subscribe path so the 16 MiB iroh-gossip allocation never happens in the first place. iroh-gossip 0.98 doesn't expose that knob; ADR 013 §Wire Framing already documents this as operator-policy territory. Will file a separate issue post-merge.
🤖 Generated with Claude Code