Skip to content

fix(protocol,node,client)!: cap every frame read at its ALPN ceiling - #2501

Merged
thiras merged 2 commits into
mainfrom
fix/frame-ceilings
Oct 17, 2026
Merged

thiras merged 2 commits into
mainfrom
fix/frame-ceilings

Conversation

@thiras

@thiras thiras commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

What

Fixes an unauthenticated memory-exhaustion DoS reported by Radeonares32.

read_frame checked every length prefix against one global 16 MiB MAX_MESSAGE_SIZE and allocated the buffer before the payload arrived. No request is larger than a few hundred bytes. A peer with no stake or funds could announce a near-16 MiB request, send most of it, and stall, holding the buffer for the 5 s read timeout. On cdn/client/v1 it was worse: serve_stream read the request before it checked the per-connection stream permit, and QUIC admits 100 bidi streams per connection. So one connection could hold about 1.6 GiB, and the only bound was the attacker's upload bandwidth × 5 s.

  • Per-ALPN frame ceilings. These replace the global cap. Each one is a protocol constant beside the messages it bounds:

    Ceiling Value Largest legitimate message
    MAX_PROBE_FRAME 1 KiB ProbeResponse + ext, 325 B
    MAX_CLIENT_CONTROL_FRAME 4 KiB StreamRequest + binding + capability, 301 B
    MAX_CHUNK_FRAME 1,048,580 B ChunkData carrying one CHUNK_BYTES
    MAX_DHT_FRAME 64 KiB full BatchStoreRequest, 59,939 B
  • No read without a ceiling. read_frame(r, max) and framing::parse_frame(buf, max) take a required ceiling, so an uncapped read cannot be written. MAX_MESSAGE_SIZE and its compile-time guard are deleted. FrameError::TooLarge is now { len: u64, max: u32 }.

  • Every read site is capped: the probe, DHT and client request readers; the node's payment-proof reader (BufferedProofReader); the node's DHT response read; and the payer's probe, StreamResponse and delivery reads. The ChunkData encoders refuse a frame above MAX_CHUNK_FRAME.

  • The stream cap is checked before the read. An over-cap cdn/client/v1 stream is reset with RATE_LIMITED before its request is read. It does not hold a buffer and costs no signature.

  • A connection-level QUIC receive window (8 MiB). The review found that the node kept noq's default unlimited connection window. A peer could park about 1.25 MB of out-of-order data per stream in the transport, below read_frame: about 125 MB per connection, on every ALPN. QUIC_CONNECTION_RECEIVE_WINDOW (8 × CHUNK_BYTES) bounds it. The per-stream window stays at the default. This also caps one connection's in-flight download at about 80 MB/s at a 100 ms round trip.

  • ADRs fixed.

    • ADR 013 § Wire Framing now has the ceiling table and the real memory bound at the default 256 handlers: 2 GiB of unread transport data, 200 MiB of client reader buffers and 16 MiB of DHT reader buffers.
    • ADR 013 no longer says operators SHOULD lower MAX_MESSAGE_SIZE (no such setting existed), and no longer claims MAX_STREAMS bounds per-peer memory.
    • ADR 005 states the over-cap stream rule.
    • ADR 022's "~2.45 KB max" FindValueResponse ignored the 200 B coverage bitmap; the real maximum is 12,375 B.

The reporter's second observation is that one source IP can occupy most of the 256 handler slots. It is slot exhaustion, not memory, and it exists without this bug, so it is filed separately as #2502.

Reviewer notes

  • Start with: crates/protocol/src/framing.rs, the four constants (message.rs, client.rs, dht.rs), crates/node/src/handlers/client/dispatch.rs (the moved permit check), and quic_transport_config in crates/node/src/runtime/mod.rs (the receive window).
  • Ceiling sizes: each one comes from the worst-case encode: full-width varints, 65 B EOA signatures, the 200 B coverage cap and full list caps. A test beside each ceiling pins the size: *_frame_ceiling_holds_the_largest_message and max_chunk_frame_is_one_full_interval.
  • Client headroom: every signature on the wire is a 65-byte EOA signature (contract-wallet owners are not accepted), so the 4 KiB client headroom is for Tier-1 extension fields.
  • Not wire-breaking: every legitimate frame fits its ceiling.
  • Rust API break, decdn-protocol only: the read_frame / parse_frame signatures, the removed MAX_MESSAGE_SIZE, and the TooLarge shape. sponsord does not use the framing API. The decdn-client snapshot is unchanged.
  • Test edits: two chunk-encoder tests probed varint widths at 2 MiB, which is now past the ceiling. They test the encoders up to 1 MiB and test the sizing function past it.
  • Mutation checks: each new test fails when its read is given MAX_CHUNK_FRAME instead. That covers the node's request, proof and DHT reads, and the requester's StreamResponse, DHT and probe reads. The over-cap test fails with the permit check back after the read. a_peer_cannot_park_more_than_the_connection_receive_window measured 19.9 MB parked across 16 streams before the window, and at most 8 MiB after.

Verification

  • cargo fmt -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo nextest run --workspace: 5,082 passed (1 existing timing flake on retry, window_pull_through_bounded_unaligned_range_pulls_only_the_span, passed 15/15 on its own both before and after this change)
  • CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items
  • INSTA_UPDATE=always cargo nextest run -p decdn-protocol --features public-api-test (snapshot diff reviewed); decdn-client snapshot unchanged
  • cargo nextest run -p decdn-e2e --features anvil-e2e: 101 passed; decdn-node anvil_settlement_e2e + anvil_bringup_shutdown_e2e: 5 passed
  • pre-commit run --all-files
  • User-visible change: CHANGELOG.md entry added (Security)
  • Design change: ADR 013, 005, 022 and appendix-observability updated
  • PR title uses an allowed type with a lowercase subject

🤖 Generated with Claude Code

https://claude.ai/code/session_0123DU1V2G3UnrwF2o9g4XHa

Every frame read checked its length prefix against one global 16 MiB
MAX_MESSAGE_SIZE and allocated the buffer before the payload arrived, though
no request is larger than a few hundred bytes. A peer with no stake or funds
could announce a near-16 MiB request, send most of it, and stall, holding the
buffer for the 5 s read timeout. On cdn/client/v1 the node read the request
before it checked the per-connection stream permit, so one connection could
hold 100 such buffers (about 1.6 GiB), bounded only by attacker bandwidth.

- Replace the global cap with per-ALPN ceilings sized to the largest
  legitimate message: MAX_PROBE_FRAME (1 KiB), MAX_CLIENT_CONTROL_FRAME
  (4 KiB), MAX_CHUNK_FRAME (one CHUNK_BYTES ChunkData) and MAX_DHT_FRAME
  (64 KiB). A worst-case encode test beside each ceiling pins its margin.
- read_frame and framing::parse_frame take a required ceiling, so no read can
  be written without one. MAX_MESSAGE_SIZE is deleted; FrameError::TooLarge
  carries { len, max }.
- Cap every read site: probe, DHT and client request reads, the payment-proof
  reader, the node's DHT response read, and the payer's probe, StreamResponse
  and delivery reads. The ChunkData encoders refuse a frame past
  MAX_CHUNK_FRAME.
- Reset an over-cap client stream with RATE_LIMITED before reading its
  request.
- ADR 013 states the ceilings and the real memory bound and drops the
  nonexistent operator setting; ADR 005 states the admit-before-read rule;
  ADR 022 corrects the DHT size table for the 200 B coverage bitmap.

Reported by Radeonares32.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0123DU1V2G3UnrwF2o9g4XHa
Copilot AI balanced review requested due to automatic review settings October 17, 2026 16:37
@thiras thiras self-assigned this Oct 17, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Security-sensitive allocation limits and concurrent-stream admission changes warrant final human validation across the affected endpoints.

No open issues 🎉

What changed in this PR

Limits frame allocations across deCDN’s protocol, node, and client to address unauthenticated memory exhaustion.

Changes:

  • Replaces the global frame limit with required, per-protocol ceilings.
  • Rejects excess client streams before reading their requests.
  • Adds boundary and rejection tests; updates protocol documentation and API snapshots.
File Description
crates/​protocol/​tests/​snapshots/​public_api__public_api.snap Records framing API changes.
crates/​protocol/​src/​message/​tests.rs Checks maximum probe message sizes.
crates/​protocol/​src/​message.rs Defines the probe ceiling.
crates/​protocol/​src/​lib.rs Exports ceilings and updates documentation.
crates/​protocol/​src/​framing/​tests.rs Tests explicit limits and early rejection.
crates/​protocol/​src/​framing/​proptests.rs Supplies limits in property tests.
crates/​protocol/​src/​framing.rs Requires read ceilings before allocation.
crates/​protocol/​src/​dht/​tests.rs Pins maximum DHT message sizes.
crates/​protocol/​src/​dht.rs Defines the DHT ceiling.
crates/​protocol/​src/​coverage.rs Updates frame-limit documentation.
crates/​protocol/​src/​client/​tests.rs Tests control and chunk boundaries.
crates/​protocol/​src/​client.rs Defines client ceilings and caps chunk encoders.
crates/​node/​tests/​support/​mod.rs Updates readers and adds prefix helper.
crates/​node/​tests/​probe_loopback.rs Tests probe ceiling enforcement.
crates/​node/​tests/​node_to_node_pull_through.rs Updates fixture read limits.
crates/​node/​tests/​node_origin_pull.rs Updates fixture read limits.
crates/​node/​tests/​dht_loopback.rs Tests oversized DHT rejection.
crates/​node/​tests/​client_loopback.rs Tests early rejection and payment exposure.
crates/​node/​src/​handlers/​probe.rs Caps inbound probe frames.
crates/​node/​src/​handlers/​dht.rs Caps inbound DHT frames.
crates/​node/​src/​handlers/​client/​wire/​tests.rs Adjusts chunk encoder tests.
crates/​node/​src/​handlers/​client/​wire.rs Updates errors and ceiling documentation.
crates/​node/​src/​handlers/​client/​mod.rs Caps requests and buffered proofs.
crates/​node/​src/​handlers/​client/​dispatch.rs Checks stream admission before reading.
crates/​node/​src/​dht/​client.rs Caps DHT response reads.
crates/​e2e/​tests/​pool_floor_ceiling_aggregate.rs Applies response and delivery limits.
crates/​e2e/​src/​client.rs Updates capture reader limits.
crates/​client/​src/​probe.rs Caps probe responses.
crates/​client/​src/​lib.rs Caps opening responses and delivery frames.
CHANGELOG.md Documents the security fix and API break.
adr/​appendix-observability.md Clarifies rejection metric meanings.
adr/​022-content-discovery.md Corrects DHT size estimates.
adr/​013-schema-evolution.md Specifies ceilings and allocation bounds.
adr/​005-protocol.md Documents early admission and chunk limits.

Review effort: Balanced

@github-code-quality

github-code-quality Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main d29e788 fix/frame-ceilings c52547b +/-
76% 76% 0%
View coverage of the 7 most impacted files.
File main d29e788 fix/frame-ceilings c52547b +/-
crates/node/src/runtime/mod.rs 26% 26% 0%
crates/protocol/src/framing.rs 93% 93% 0%
crates/node/src...ndlers/probe.rs 86% 86% 0%
crates/node/src...s/client/mod.rs 90% 91% +1%
crates/node/src.../client/wire.rs 92% 93% +1%
crates/node/src/dht/client.rs 80% 81% +1%
crates/node/src...handlers/dht.rs 76% 80% +4%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 17, 2026 17:34 UTC

…view gaps

Review of #2501 found the node kept noq's unlimited connection receive window.
A peer could send each stream's later bytes and hold back its first, parking
about 1.25 MB of out-of-order data per stream below read_frame: about 125 MB
per connection, on every ALPN, which the frame ceilings never see.

- Set an 8 MiB connection receive window (QUIC_CONNECTION_RECEIVE_WINDOW, eight
  CHUNK_BYTES intervals). The per-stream window stays at the default.
- ADR 013 states the real bound at the default 256 handlers (2 GiB transport,
  200 MiB client reader, 16 MiB DHT reader) and drops the contract-wallet
  headroom claim: every wire signature is a 65-byte EOA signature.
- FrameError::TooLarge.len is u64, so write_frame's over-u32 refusal reports
  the real length.
- Add requester-side tests for oversized StreamResponse, DHT and probe
  responses; pin the proof-frame refusal's cause through its span; test the
  chunk frame encoder at exactly MAX_CHUNK_FRAME and one leaf past it.
- Fix docs the ceilings made stale (DHT size claims, metrics, CHANGELOG).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0123DU1V2G3UnrwF2o9g4XHa
@thiras
thiras merged commit fd47d44 into main Oct 17, 2026
31 checks passed
@thiras
thiras deleted the fix/frame-ceilings branch October 17, 2026 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants