Skip to content

node: unknown/absent payment channel is not validated before bytes are served — free egress of the first voucher interval #848

Closed

Description

@alpergundogdu

Severity: Medium

Summary

serve_stream looks up the payment channel as an Option and proceeds to sign ok: true and stream bytes even when the channel is None (unknown / never-opened). The channel is only validated at the first voucher boundary, by which point up to one full voucher interval (clamped to a 1 MB floor) — or the entire blob, if smaller — has already been delivered for free.

Where

  • crates/node/src/handlers/client.rs:525-582 (serve_stream): let channel = self.channels.lock().await.get(&channel_id).cloned(); — a None is not rejected before delivery.
  • The owner-binding check at :536-544 runs only when both verified_client and channel are Some, so it does not close the unknown-channel case.
  • :570-582 signs ok: true and calls deliver, which streams all chunks up to interval_bytes.
  • crates/node/src/handlers/client.rs:589-665 (deliver): the closing/interval voucher is collected only after unvouchered >= interval_bytes; interval_mb is clamped self.voucher_interval_mb.min(proposed).max(1) (1 MB floor at :549-552).
  • Rejection happens only in collect_voucher (Some(channel) else { write_reject(WrongChannel); return Rejected }).

Impact

A remote peer with no payment channel at all receives min(blob_size, ~1 MB) of any blob the node caches, for free, per stream — repeatable across streams/connections, bounded only by the dispatch limiter and the 100-stream cap. Blobs smaller than the interval are served in full before the closing voucher is even requested. This is more permissive than the "channels must be pre-persisted" model documented in the module header (#327).

Suggested fix

Reject with StreamError/WrongChannel (before signing ok: true) when the channel lookup returns None. Optionally combine with the on-chain NodeId → client address lookup noted as out-of-scope in #327 to also close the unbound-peer residual.

Notes

Found during a full-repo audit; verified by reading serve_stream/deliver. Related: per-region bandwidth accounting also omits this first-interval traffic (client.rs:781-783), so the leech egress is invisible in regionStats — worth fixing alongside.

Activity

  1. added
    kind:bug
    kind:security
    prio:medium
    rust
    on Jun 9, 2026
  2. github-actions commented on Jun 9, 2026

    @github-actions

    🎯 Triage report

    serve_stream in crates/node/src/handlers/client.rs signs ok: true and begins streaming bytes before verifying that a payment channel exists. Because the None channel path bypasses the owner-binding guard (line 536 only fires when both verified_client and channel are Some), any peer that omits channel setup receives up to min(blob_size, ~1 MB) per stream for free — repeatable and invisible in regionStats. The fix is a targeted early-reject when channel.is_none().

    📊 Assessment

    Dimension Value Reasoning
    Type Bug Logic defect: validation gate fires after bytes are already delivered
    Labels bug, security, medium, technical Economic exploit with clear reproduction path; medium severity per author
    Coding agent Suitable Precise line references, self-contained fix, well-defined acceptance criteria

    🔗 Similar issues

    💡 Notes and suggestions

    Root cause (confirmed by code reading)

    serve_stream (:525–582) fetches channel as Option<Arc<Mutex<ChannelDeliveryState>>>. The guard at :536–544 only fires when both verified_client and channel are Some. When channel is None the guard is silently skipped, ok: true is signed at :556–565, and deliver is called with channel: None. In deliver, voucher collection only happens at the interval boundary; for blobs ≤ the interval the closing voucher is the only payment gate — but bytes are already gone by then.

    Suggested fix (two changes)

    1. After :527, add an early reject:
    // Reject immediately if no channel is registered — do not deliver any bytes.
    if channel.is_none() {
        return self
            .respond_error(&mut send, &req, StreamError::WrongChannel)
            .await;
    }

    This is the critical fix. It aligns runtime behaviour with the module-doc invariant from #327 and closes the free-egress window before any bytes leave the node.

    1. Secondary (worth fixing alongside per the issue notes): per-region bandwidth tracking at :781–783 (regionStats) does not account for traffic from None-channel streams. Once fix (1) lands this becomes moot for the exploit path, but the accounting gap may still exist for legit streams that hit an error before the first voucher — worth auditing.

    Sub-task checklist

    • Add channel.is_none() early-reject before sign_response in serve_stream
    • Add a unit/integration test: open a stream with an unknown channel_id, assert the connection receives WrongChannel and zero payload bytes
    • Verify regionStats egress accounting covers the error-path bytes (secondary, lower priority)
    • Consider a tracing::warn! on the rejection to surface abuse attempts in operator logs

    Dispatch limiter note: The existing dispatch limiter and 100-stream cap provide partial blast-radius control today, but they do not prevent the leak — they only bound per-connection concurrency. The fix must be at the protocol gate.

    Generated by Agentic Triage for issue #848 · sonnet46 581.2K · ◷

    Add this agentic workflows to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
  3. self-assigned this
    on Jun 10, 2026
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:mediumrust

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions