Skip to content

serve: hoist a pre-spend deposit check above the buffered/range/local fill tiers #1519

Closed

Description

@thiras

Found by the multi-agent review of #1518, and independently by two reviewers. Pre-existing — #1518 did not introduce it — but #1518 is where the two deposit guards were brought into step, which is what makes the asymmetry visible.

The gap

serve_stream (crates/node/src/handlers/client/dispatch.rs) runs its cache-miss fill ladder before the channel is resolved, and three of the four tiers spend money with no deposit check:

Site Tier Spends
dispatch.rs try_range_pull_through origin range pull (#823) S3/R2 egress
dispatch.rs try_local_populate local origin (#1116) operator's own origin egress
dispatch.rs try_pull_through → cache.populate buffered node→node real upstream USDC (the paid Peer origin)
dispatch.rs → serve_via_window_pull_through window pull-through guarded — window.rs checks headroom before open_progressive_pull

The only thing in front of the first three is pull_authorized (crates/node/src/handlers/client/fill.rs), which checks a verified binding, channel existence, signer match, and funder denylist — not deposit. The #1516 direct-serve gate then runs after all of them.

Why it matters

A channel with 1 base unit of headroom satisfies pull_authorized perfectly. So:

The attacker gets nothing — #1516 closed the free-egress half — but the operator still pays. It is the same wallet drain with the payout removed. The leech-shed budget (leech_admit) does not help either: it lives only in window.rs.

What the operator sees is decdn_serve_stream_rejected_insufficient_deposit_total climbing. That reads as "the guard is working", and on this path it means the opposite: the pull already completed and the money is gone. #1518 corrected the metric doc and ADR 037 to say so, but the doc is the only mitigation right now.

Proposal

Hoist a cheap headroom floor to just after channel resolution — it needs no total_bytes, so it can run before the fill ladder:

headroom >= min_payment(credit_window(interval_bytes), rate)

i.e. "can this channel pay for anything at all". window.rs's guard is the shape to copy (whole-blob ceiling when max_blob_size_bytes is finite, else the speculative window). The existing span-capped gate stays where it is as the exact per-request check.

Note this requires moving the channel resolution above the fill ladder, or duplicating a cheap lookup — worth checking which reads better against the ADR-005 ordering comments in serve_stream.

Acceptance

  • A 1-base-unit channel requesting an absent hash does not cause an origin fetch or an upstream dial.
  • Test: seed a dust channel, configure a pull-through origin, request an absent hash, assert the origin/upstream was never contacted and the reject counter fired.
  • The window path's existing guard is unchanged.

Activity

  1. added
    kind:bug
    rust
    on Jul 29, 2026
  2. added
    prio:high
    kind:security
    on Jul 29, 2026
  3. self-assigned this
    on Jul 30, 2026
  4. added 4 commits that reference this issue on Jul 30, 2026
    4c66411
    1084585
    169cf8d
    b1a5962
  5. added a commit that references this issue on Jul 30, 2026
    ed583b7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:bugkind:securityprio:highrust

Type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions