Skip to content

client-pull: hostile provider bills the full buffered stream before any byte verifies when total_bytes is inflated #1985

Closed

Description

@thiras

Severity: medium-high — attack-surface review of the paid delivery path. Sibling finding: corrupt-at-rest serving (filed as #1984); both trace to the same root — bytes are proven once, at an edge, always after money moves.

The gap

The buffered receive path pays for the whole stream before any byte is verified:

  • expected_wire is derived from the peer-signed total_bytes claim (crates/client-pull/src/lib.rs:2056, fed by the signed StreamResponse). A hostile provider signs its own inflated claim — that signature proves attribution, not truth.
  • receive_and_pay releases a reveal per 1 MiB chunk as bytes arrive and a closing residual voucher at end-of-stream (lib.rs:2352, 3281). BLAKE3 verification runs only after the loop completes (lib.rs:2116) on this path. Reveals already released are irreversible; nothing about them is refundable if decode then fails.
  • The progressive path (open_progressive_pull → PullReader/sink feeding the bao decoder) decodes incrementally off the wire — there a corrupt group aborts within ~one chunk-group of arrival. The asymmetry is the point: exposure depends on which receive path a caller happens to use.

So on the buffered path (loopback fills / shared pulls), "valid-framed garbage billed up front" is a deliberate abuse of an otherwise accepted pay-before-prove design, not just generic corruption.

What already bounds it (corrections to the naive exploit)

Bound Effect
max_received_wire = aligned wire size of cache.max_blob_size_mb (#1895, default 50 GB), enforced on bytes that actually arrive, aborting before paying the crossing chunk (lib.rs:2326) Caps the bleed even with a fully-inflated claim — unless the buyer sets max_blob_size_mb: 0 (= unlimited)
Cumulative overrun guard vs expected_wire (lib.rs:2313) Over-billing scales exactly with the inflated claim, no further
Per-capability spendingCap + pool spendable Hard on-chain bound; note genuine_exhaustion auto-prompts top-up (lib.rs:1911), letting a sharp attacker extend the bleed past the original deposit
Rate inflation is already closed: the effective ceiling is min(probe quote, config absolute) and RateAboveCeiling aborts before the first voucher (lib.rs:2031); probe-relative binding makes completed deliveries non-challengeable Only bytes inflate

Per-stream loss ≈ min(inflated_claim, 50 GB-wire) × rate; time-bound by throughput (~44 s at 10 Gbps). Fleet-wide, repeated per discovery attempt.

Impact

Pure billing-for-garbage on the buffered path: honest-rate payment for undelivered/undeliverable bytes, bounded by the buyer's own ceilings but shifted entirely onto victims before proof exists. Same economics as #1984 plus the inflation lever, minus persistence.

Refs: #1984, ADR 005 §Payment metering, ADR 038 §Receive side.

Activity

  1. added
    kind:security
    design:economics
    rust
    on Sep 10, 2026
  2. thiras commented on Sep 10, 2026

    @thiras
    ContributorAuthor

    Recommendation

    1. Unify both receive paths on incremental verification (the fix).

    The end-of-stream whole-buffer decode (decode_verified_range at lib.rs:2116, called only by fetch_inner_once) is the cascade origin: it exists solely because this path drains to a BytesMut instead of decoding as frames arrive. The progressive path already has the machinery — PullReader + sink feeding DecodeResponseIter, with classify_decode_error splitting hash-mismatch from truncation. Route the buffered path's buffer through that same decoder as bytes land, then the distinct second decoder and its completeness special-cases collapse into one streaming implementation.

    Effect: hostile-provider overpayment drops from ≤ 50 GB-wire to ≈ one chunk group (16 KiB content + proof slack) on every path; detection latency becomes arrival latency, matching what the reveal cadence already implies. Wire format untouched; localised to client-pull.

    2. Considered and kept out: deferring the closing residual voucher until after decode — recovers < 1 MiB of exposure for a new commit-ordering rule interacting with the throughput-floor pause window.

    3. Considered and kept out: refund claims / per-stream escrow — node-cooperative refunds are voidable by exactly the party they'd constrain, and a new on-chain record fails the live-consumer gate today. The #1984 "false delivery" slash thread is the strict subset worth revisiting if measurements ever justify contract surface.

    4. Document rather than build: max_blob_size_mb and the capability spendingCap are the intended per-channel exposure bounds ("0 = unlimited" deserves a loud warning); and the dispute window adjudicates watermarks/rate evidence, not content quality — buyers absorb failed-delivery losses by design.

    Tests to write

    1. Ledger invariant: Σ vouchers committed == f(wire bytes received) for a scripted garbage provider under an inflated claim — including the abort-before-pay behaviour at max_received_wire.
    2. Buffered-path property test: garbage framing + inflated total_bytes ⇒ committed ≤ min(spendingCap remaining, ceiling-wire × quoted rate).
    3. Streaming bound: corrupt group at offset K via the progressive driver ⇒ paid span ≤ K + alignment slack (pins the buffered-vs-progressive asymmetry the unification removes).
    4. Documentation-as-test: seller redeems signed vouchers after a failed-delivery verify — pins accepted irreversibility so any future refund mechanism shows up as a deliberate diff.
  3. yigitdot commented on Sep 11, 2026

    @yigitdot
    Contributor

    Verification against main (8b437de5)

    Mechanism is valid; blast radius is wrong.

    Holds:

    • expected_wire derives from the peer-signed, unbounded total_bytes (lib.rs:2045-2046; the comment at 2008-2015 already calls it "peer-controlled and unverified").
    • receive_and_pay releases a reveal per 1 MiB as bytes land (lib.rs:2341-2350) plus the closing residual; decode_verified_range runs only after the loop at lib.rs:2105 and is called only from fetch_inner_once. Buffer-then-decode, not incremental.
    • The progressive path (open_progressive_pull → PullReader → ResponseDecoder, ranged_store.rs:558-599, admit_store.rs:138-148) aborts at the first bad group. Asymmetry confirmed.
    • All four bounds check out at the cited lines: max_received_wire (2054-2066, enforced at 2315-2320 before pay; 0 = unlimited), overrun guard (2302-2306), RateAboveCeiling (2020-2022), genuine_exhaustion (1900-1925). Effective default bound is min(50 GB, cache_size_mb) × rate.

    Does not hold:

    • "loopback fills / shared pulls" reach the buffered path. stream_fetch, stream_fetch_tracked, stream_fetch_tracked_with_progress, stream_fetch_shared have zero production callers in crates/node/src or crates/cli/src — only doc-comment mentions. Node cache-miss pulls (node_origin/pull_leg.rs:391,744,811,1100) and CLI fetch (commands/fetch.rs:1804,1865,1884,2067,2207) all use open_progressive_pull / PeerSource / drive. The only code callers are crates/e2e/src/client.rs (test-infrastructure crate) and integration tests under crates/node/tests/.

    So on main no buyer is exposed to this today; the exposed surface is test scaffolding.

    Two comments in lib.rs are wrong and should be fixed regardless:

    • lib.rs:1987-1993 claims node-to-node loopback/shared-channel callers reach fetch_inner_once. None exist.
    • lib.rs:2330-2333 says a reveal is released "only AFTER the bytes it pays for have been received and verified, so the payer's exposure stays at zero." On this path the bytes are received but not verified when the reveal fires.

    Suggested rescope: keep open, narrow to one of: (a) delete the stream_fetch* buffered path and move crates/e2e + the integration tests onto the progressive driver, so there is one receive implementation; or (b) unify as recommendation 1 describes. (a) is less code. Either way, fix the two comments above, and note that ADR 038's acceptance criterion "a corrupt chunk group is rejected at that group, not only at finalization" is what the surviving path must keep satisfying.

  4. moved this from Backlog to In progress in deCDNon Sep 11, 2026
  5. moved this from In progress to Done in deCDNon Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

design:economicskind:securityrust

Type

No type

Fields

Priority

None yet

Projects

  • Status
    Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions