Repository navigation
fix(node): reject unknown payment channel before serving any bytes (#848) - #875
Conversation
) `serve_stream` looked up the payment channel as an `Option`, signed `ok: true`, and streamed bytes even when the channel was `None` (unknown / never opened). The unknown channel was only caught later in `collect_voucher` (mid-stream `WrongChannel`), by which point up to one voucher interval (the negotiated cadence, default 1 MB) — or the whole blob, if smaller — had already shipped for free, repeatable per stream. Add a pre-serve gate in `serve_stream`: when the channel lookup returns `None`, refuse with the delivery-side `StreamError::NotFound` before signing the success response. `NotFound` mirrors the existing owner-mismatch gate and avoids leaking channel existence; the mid-stream `WrongChannel` reason cannot ride in the initial `StreamResponse`. With the channel now non-optional, the owner-binding check simplifies from `(Some, Some)` to `if let Some(client)`. Rewrite `client_unknown_channel_is_rejected` to assert the server's `StreamResponse` directly (`!ok` + `NotFound`) via `raw_request`, and use a 1.5 MiB blob so the gate is proven to fire independent of blob size. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request addresses issue #848 by refusing stream requests on unknown or never-opened channels pre-serve, returning a StreamError::NotFound error before any bytes are delivered. This prevents clients from downloading up to one voucher interval of data for free before a mid-stream rejection occurs. The verified client binding check has been simplified accordingly, and the loopback test client_unknown_channel_is_rejected has been updated to verify this pre-serve refusal behavior directly on the raw StreamResponse. There are no review comments, so I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
This PR fixes a paid-delivery security gap in the node stream handler: requests that reference an unknown / never-opened payment channel are now rejected before a success response is signed and before any blob bytes can be served (closing the “free first voucher interval” egress described in #848).
Changes:
- Add a pre-serve gate in
serve_streamto refuse unknown channels with a signedStreamResponse { ok: false, error: NotFound }. - Simplify the verified-client owner binding check now that
channelis guaranteed present on the serve path. - Rewrite the loopback test to assert directly on the server’s first
StreamResponseusing the raw request path, and use a 1.5 MiB blob to ensure the gate is independent of blob size.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
crates/node/src/handlers/client.rs |
Reject unknown channels pre-serve with NotFound, preventing any bytes from being delivered before channel validation. |
crates/node/tests/client_loopback.rs |
Updates the regression test to assert the server-side refusal response directly (and with a payload large enough to cross an interval if served). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 85.93% (was 85.93%, ▼ 0.01%) — 34328/39951 lines
History
|
…884) * feat(node): meter refused serve_stream paid-delivery requests (#876) Every paid-delivery reject branch in `serve_stream` refused with a signed `StreamResponse { ok: false }` and a `tracing::warn!` but incremented no metric, so a refused stream was invisible to operator dashboards — there was no way to alert on "rate of refused streams" or distinguish a misconfigured client from an abuse campaign. This is the operator-side counterpart to the #848/#875 silent-failure work. Add six per-reason reject counters (the `iroh_metrics` backend has no runtime labels, so one Counter per reason matches the existing `dispatch_rejected_*` / `dht_rate_limit_rejected_*` convention): decdn_serve_stream_rejected_{evicted_since_probe,cache_miss,internal_error, blob_too_large,unknown_channel,owner_mismatch}_total A private `ServeRejectReason` enum is threaded into the central `respond_error` helper, which increments the matching counter at one site. The reason is the single source of truth: `wire_error()` derives the signed `StreamError`, so the three branches that deliberately share the wire `NotFound` (to avoid leaking channel existence) stay wire-indistinguishable while remaining separately countable server-side — and an inconsistent error/reason pairing is unrepresentable at the call sites. Tests: a metrics unit test asserts all six counters start at zero and each method bumps exactly its own counter; five loopback tests assert the correct counter advances on a real refusal (all reasons except InternalError, which needs a faulting-cache double — deferred). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> * docs(node): sharpen serve_stream reject-counter comments (#876) Address PR review nits: name the three wire-conflated NotFound reasons explicitly instead of the ambiguous "reasons below", and scope the "finer-grained than the wire" claim to the three NotFound cases (the other three reasons map 1:1 to distinct wire errors). Comment-only; no behavior change. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
What
Fixes #848 — a node served up to one voucher interval (default ~1 MB) or the whole blob for free to any peer requesting paid delivery on an unknown / never-opened payment channel.
Root cause
serve_streamlooked up the channel as anOption, signedok: true, and calleddelivereven when the lookup returnedNone. The unknown channel was only caught later incollect_voucher(mid-streamVoucherRejected { WrongChannel }) — after bytes had already shipped. For a sub-interval blob the entire blob shipped before the closing voucher was rejected; for a larger blob, the first full interval shipped. Repeatable per stream, bounded only by the dispatch limiter / stream cap. This contradicted the "channels must be pre-persisted" model (#327).Fix
Add a pre-serve gate in
serve_stream: when the channel lookup isNone, refuse with the delivery-sideStreamError::NotFoundbefore signing the success response — no bytes flow.NotFoundmirrors the existing owner-mismatch gate and avoids leaking channel existence. The mid-streamWrongChannelreason cannot ride in the initialStreamResponse(it'sis_mid_stream-only).channelnow non-optional, the owner-binding check simplifies from(Some, Some)toif let Some(client)(behavior-preserving — the old tuple only fired when both wereSome).collect_voucherNonearm is now unreachable from its sole caller; kept as a defensive backstop with a comment noting so.Test
Rewrote
client_unknown_channel_is_rejectedto:StreamResponsedirectly (!ok+NotFound) via theraw_requestidiom — proves the success/serve path was never entered, rather than inferring from the buyer's error string;Verification
cargo nextest run -p decdn-node→ 568/568 passedcargo clippy -p decdn-node --all-targets→ cleancargo fmt -- --check→ cleanOut of scope (follow-up)
Serve-path rejections increment no metric — a pre-existing observability gap across all reject branches in
serve_stream, amplified by this issue. Tracked separately so an operator can alert on refused-stream rate.🤖 Generated with Claude Code