Repository navigation
fix(protocol,node,client)!: cap every frame read at its ALPN ceiling - #2501
Merged
Merged
Conversation
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
There was a problem hiding this comment.
🔵 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
Code coverage overviewLanguages: Rust Rust / code-coverage/cargo-llvm-cov
View coverage of the 7 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
…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
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.
What
Fixes an unauthenticated memory-exhaustion DoS reported by Radeonares32.
read_framechecked every length prefix against one global 16 MiBMAX_MESSAGE_SIZEand 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. Oncdn/client/v1it was worse:serve_streamread 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:
MAX_PROBE_FRAMEProbeResponse+ ext, 325 BMAX_CLIENT_CONTROL_FRAMEStreamRequest+ binding + capability, 301 BMAX_CHUNK_FRAMEChunkDatacarrying oneCHUNK_BYTESMAX_DHT_FRAMEBatchStoreRequest, 59,939 BNo read without a ceiling.
read_frame(r, max)andframing::parse_frame(buf, max)take a required ceiling, so an uncapped read cannot be written.MAX_MESSAGE_SIZEand its compile-time guard are deleted.FrameError::TooLargeis 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,StreamResponseand delivery reads. TheChunkDataencoders refuse a frame aboveMAX_CHUNK_FRAME.The stream cap is checked before the read. An over-cap
cdn/client/v1stream is reset withRATE_LIMITEDbefore 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.
MAX_MESSAGE_SIZE(no such setting existed), and no longer claims MAX_STREAMS bounds per-peer memory.FindValueResponseignored 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
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), andquic_transport_configincrates/node/src/runtime/mod.rs(the receive window).*_frame_ceiling_holds_the_largest_messageandmax_chunk_frame_is_one_full_interval.decdn-protocolonly: theread_frame/parse_framesignatures, the removedMAX_MESSAGE_SIZE, and theTooLargeshape. sponsord does not use the framing API. Thedecdn-clientsnapshot is unchanged.MAX_CHUNK_FRAMEinstead. That covers the node's request, proof and DHT reads, and the requester'sStreamResponse, 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_windowmeasured 19.9 MB parked across 16 streams before the window, and at most 8 MiB after.Verification
cargo fmt -- --checkcargo clippy --workspace --all-targets --all-features -- -D warningscargo 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-itemsINSTA_UPDATE=always cargo nextest run -p decdn-protocol --features public-api-test(snapshot diff reviewed);decdn-clientsnapshot unchangedcargo nextest run -p decdn-e2e --features anvil-e2e: 101 passed;decdn-nodeanvil_settlement_e2e+anvil_bringup_shutdown_e2e: 5 passedpre-commit run --all-filesCHANGELOG.mdentry added (Security)🤖 Generated with Claude Code
https://claude.ai/code/session_0123DU1V2G3UnrwF2o9g4XHa