Repository navigation
fix(node): batch fix for the node security audit issues - #2712
Conversation
`register_lane` recorded the fresh zero lane before the atomic vacant-slot insert. Two first streams on one lane could both record it, and the second record could overwrite a voucher the first stream's lane had already recorded, rolling the stored frontier, amount and signature back to zero. The record now runs inside the `Entry::Vacant` arm, under the slot guard; a failed record leaves the slot vacant. Closes #2701 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d-stream cap check After a restart the projection seeds an unfolded pool from one `getPool`, and its per-signer total counts only redemptions folded after the seed. `ResolvingPoolView::signer_spent_cached` read that total alone, so the mid-stream signer cap check ignored everything the signer spent before the seed and kept serving bytes the on-chain `redeemMany` would not pay for. It now answers from the cached admit-path `getAuthorization` read brought up to the fold (`spent + folded_since`), the number admission already uses, and falls back to the projection only when no registered read is held. A lane's first post-read fold counts its whole cumulative, so the error runs high by at most the read's `spent`: a stream near the cap stops early, never late. Closes #2711 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ts lanes The redeemer's pool view learns a pool only from folded events and the admit path's reads, and the watcher resumes at its checkpoint, so after a restart a pool opened before it stayed unknown and passed planning. Once that pool was Closing past its deadline, its lanes were still submitted; `redeemMany` reverted `PoolClosed`, taking the whole batch, and the same lanes reverted again on every sweep. Once a cycle's lanes clear the redemption floor, `resolve_unknown_pools` reads each pool the projection does not hold with one `getPool` (eight at a time) and seeds the projection with `record_resolved`. A lane whose pool is absent, `Closed`, past its close deadline or unreadable stays out of the submit and counts on `redemption_skipped_insolvent`. A failed read is a chain fault, so parked lanes stay parked. A seeded pool is known from then on, and the watcher folds its close events, so no separate `PoolClosed` revert decoding is needed. Closes #2692 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The admin JSON-RPC server answered any request on its loopback port. A page the operator opened could reach that port through DNS rebinding and call `evict` (persisted to `evicted.log`) or `drain` (shuts the node down). The server now runs a jsonrpsee `HostFilterLayer` that allows only `127.0.0.1:*` and `localhost:*`, so a rebinding page's own domain is refused while SSH tunnels and port mappings keep working. A small tower layer answers `403` to any request carrying an `Origin` header, which every browser request does and no admin client does. Batch requests are disabled; every client sends one call per request. Closes #2690 Co-Authored-By: Claude Opus 5.5 <[email protected]>
ADR 022 restricts the routing pool to bonded operators, but the routing table admitted every inbound peer (`note_peer_seen`) and every `closer_nodes` id from bucket refresh and bootstrap, and a full bucket evicted its oldest entry unconditionally. Free NodeIds could push out the bonded entries, so publish fan-out and lookup seeds went to non-participants and discovery fell back to the origin directory. `RoutingTable::insert_active` refuses a peer the staker set does not hold, and every production write uses it. On overflow it evicts an entry that has unbonded or whose dial is cooling before the least-recently-seen one. `closest_active` / `closest_active_unbounded` skip an entry that unbonded after it entered, and serve the FindNode/FindValue answers, the lookup seed and the republish fan-out. Ping-before-evict stays out: only a bonded peer can enter, so each displacement costs the attacker a bond. Closes #2708 Co-Authored-By: Claude Opus 5.5 <[email protected]>
`cdn/client/v1` had no per-request limit: only the per-connection limiter and the stream cap gated it. Every refusal past them signs a response, and an origin-only node probed its backend with a HEAD for each unseen hash before any lane or payment check, so unpaid requests could spend node CPU and origin requests without bound. A `ServeRateLimiter` over the shared `ThreeLayerRateLimiter` engine (per-peer, per-IP, global) is checked once per stream right after the stream permit and before the request is read. A refused stream is reset with `RATE_LIMITED` and no signed response (`ResetCause::RateLimited(layer)`), and the dispatch sink counts it on the layer's `decdn_serve_rate_limit_rejected_*_total`, which join `INBOUND_FAILURE_REASONS`. Config lives under a new `[serve.rate_limit]` section, surfaced in the schema, resolver, `ResolvedServe`, DEFAULT_CONFIG, the validate summary and the reload warning; the runtime runs a keyspace GC for it like the probe limiter's. ADR 005 gains § Request rate limiting, and the observability appendix lists the new series. Closes #2694 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…reads At admission an unseen `pool_id` cost one `getPool` and an unseen signer one `getAuthorization`. The negative cache is per key and capped, so a stream of requests for fresh random pool ids paid one RPC each, with no global bound, and could spend the operator's RPC quota until the blacklist watcher stalled and the node refused every serve. A request with no verified client binding names no lane and can never be served, so `serve_stream` now refuses it `NotFound` (`OwnerMismatch`) before the pool read. A bound request still reads, because a registered signer sends no capability and its `Unfunded` refusal needs `getAuthorization`. `ResolvingPoolView` gives every admission `getPool` / `getAuthorization` a slot from a node-wide semaphore of `ADMIT_CHAIN_READ_CONCURRENCY` (16); coalesced waiters take none, and the wait counts against the read's timeout. Closes #2706 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The shared `ThreeLayerRateLimiter` behind the probe, DHT and serve limiters charged global → per-IP → per-peer. A request that the peer's own bucket then refused had already spent a token of the node-wide budget, so one NodeId flooding at the global rate starved every other requester even though its per-peer cap admitted only a small part of the flood. `try_admit_one` now charges per-peer → per-IP → global, so a request a keyed layer refuses spends no global token. A request that both its own bucket and the global cap would refuse counts on the keyed layer's counter. The batch stage-2 accounting keeps its per-unit equivalence. ADR 005 and ADR 022 state the narrowest-first order; the DHT order tests pin it, and a new test shows a refused flooder leaves the global budget to other peers. Found by an automated security review of the cdn/client/v1 limiter (#2694). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…g a fault The admission read cap (#2706) put the wait for a slot inside the read's timeout. Under a flood, an honest pool's `getPool` could time out while it waited, and the timeout was negative-cached as a pool fault, so the pool stayed refused for `RESOLVE_FAULT_TTL` after the flood eased. A read now waits up to `ADMIT_CHAIN_READ_SLOT_WAIT` (5 s) for a slot, and its own timeout starts once it holds one. A request that finds no slot in time is refused with nothing cached, so the pool's next request reads again. The wait is shorter than the read timeout, so a refused request answers before the reads ahead of it time out. Found by an automated security review of #2706. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…reat table The architecture overview's threat table now names the cdn/client/v1 request limiter and admission-read cap (ADR 005 § Request rate limiting) against unpaid request floods, and the bonded-only routing table (ADR 022 § Routing Table) against DHT flooding. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Code coverage overviewLanguages: Rust Rust / code-coverage/cargo-llvm-cov
View coverage of the 10 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
There was a problem hiding this comment.
🟡 Changes recommended
Pool resolution timeouts can exceed the shutdown sweep’s 15-second deadline, preventing reconciliation and submission for funded pools and delaying subsequent cutoff sweeps.
1 open issue
What changed in this PR
This PR addresses seven node security audit issues across payment handling, admin RPC, DHT routing, and request admission.
Changes:
- Protects lane persistence, accounts for pre-restart signer spending, and resolves unknown pools before redemption.
- Adds serve-request rate limits, bounds concurrent admission reads, and restricts admin HTTP requests.
- Filters DHT routing by active stake and updates regression tests, configuration, metrics, and documentation.
| File | Description |
|---|---|
crates/node/tests/sighup_signal.rs |
Adds serve defaults to the signal-test fixture. |
crates/node/tests/node_origin_pull.rs |
Marks discovery fixture peers as bonded. |
crates/node/tests/dht_lookup.rs |
Gives lookup-chain servers bonded identities. |
crates/node/tests/dht_integration.rs |
Bonds holders in referral fixtures. |
crates/node/tests/dht_bootstrap.rs |
Tests bonded routing and updates background-task fixtures. |
crates/node/tests/client_loopback.rs |
Tests early request resets and rejection without pool reads. |
crates/node/tests/bucket_refresh_clock.rs |
Supplies the refresh task's staker set. |
crates/node/tests/anvil_bringup_shutdown_e2e.rs |
Adds serve defaults to the lifecycle fixture. |
crates/node/src/runtime/tests.rs |
Updates runtime configuration fixtures. |
crates/node/src/runtime/reload/tests.rs |
Updates reload configuration fixtures. |
crates/node/src/runtime/reload.rs |
Warns that serve-limit changes require restart. |
crates/node/src/runtime/mod.rs |
Wires serve limiting, cleanup, and DHT stake checks. |
crates/node/src/rate_limit/tests.rs |
Checks serve configuration mapping and defaults. |
crates/node/src/rate_limit.rs |
Charges peer and IP buckets before the global bucket. |
crates/node/src/pool_view.rs |
Clarifies cached signer-spend semantics. |
crates/node/src/payment_settlement/tests.rs |
Covers read limits, signer spending, and unknown-pool resolution. |
crates/node/src/payment_settlement.rs |
Bounds admission concurrency and resolves settlement state. |
crates/node/src/metrics.rs |
Adds serve-limit counters and tracking gauges. |
crates/node/src/handlers/serve_rate_limit.rs |
Introduces the serve-specific limiter wrapper. |
crates/node/src/handlers/probe.rs |
Updates comments describing limiter order. |
crates/node/src/handlers/probe_rate_limit.rs |
Documents peer-first limiter ordering. |
crates/node/src/handlers/mod.rs |
Exports the serve limiter module. |
crates/node/src/handlers/dht.rs |
Filters learned peers and referrals by active stake. |
crates/node/src/handlers/client/tests.rs |
Tests lane-registration races and restart spending. |
crates/node/src/handlers/client/outcome/tests.rs |
Checks rate-limit failure attribution. |
crates/node/src/handlers/client/outcome.rs |
Records rate-limit resets by rejecting layer. |
crates/node/src/handlers/client/mod.rs |
Serializes initial lane persistence and stores the limiter. |
crates/node/src/handlers/client/dispatch.rs |
Limits streams early and rejects unbound requests before chain reads. |
crates/node/src/dht/staker_set.rs |
Adds an all-staked unit-test helper. |
crates/node/src/dht/routing/tests.rs |
Tests stake filtering and eviction preference. |
crates/node/src/dht/routing.rs |
Adds bonded insertion and filtered peer selection. |
crates/node/src/dht/rate_limit/tests.rs |
Tests limiter ordering and global-budget protection. |
crates/node/src/dht/rate_limit.rs |
Updates limiter-order documentation. |
crates/node/src/dht/publish/tests.rs |
Supplies stake context to publication tests. |
crates/node/src/dht/publish.rs |
Restricts publication targets to bonded peers. |
crates/node/src/dht/lookup/tests.rs |
Updates lookup fixtures for stake-aware seeding. |
crates/node/src/dht/lookup.rs |
Seeds lookups from bonded peers. |
crates/node/src/dht/bucket_refresh.rs |
Filters refresh referrals by active stake. |
crates/node/src/dht/bootstrap.rs |
Checks stake before inserting seeds and referrals. |
crates/node/src/admin/origin_guard.rs |
Rejects admin requests carrying an Origin header. |
crates/node/src/admin.rs |
Filters Host headers and disables batches. |
crates/common/src/config/types.rs |
Defines optional serve-rate-limit configuration. |
crates/common/src/config/tests.rs |
Tests serve defaults, overrides, and validation. |
crates/common/src/config/resolved.rs |
Adds resolved serve settings and defaults. |
crates/common/src/config/mod.rs |
Resolves and validates serve-limit settings. |
crates/cli/tests/config_validate.rs |
Updates the configuration-validation fixture. |
crates/cli/tests/admin_rpc.rs |
Tests Host, Origin, and batch restrictions. |
crates/cli/src/commands/config/tests.rs |
Checks the template includes serve settings. |
crates/cli/src/commands/config.rs |
Exposes serve limits in templates and validation output. |
CHANGELOG.md |
Records security fixes and behavior changes. |
adr/architecture.md |
Updates the threat-defense overview. |
adr/appendix-observability.md |
Documents serve-limit metrics. |
adr/appendix-local-admin-http.md |
Documents admin HTTP restrictions. |
adr/022-content-discovery.md |
Specifies bonded routing and limiter order. |
adr/005-protocol.md |
Documents serve-request limits and peer-first ordering. |
adr/003-payments.md |
Documents admission-read and pre-redemption checks. |
Review effort: Balanced
…olved pools apart Review follow-ups for #2692. `resolve_unknown_pools` read every unknown pool before any lane reached the submit, so after a restart an RPC outage cost one 3 s timeout per unknown pool, eight at a time. Enough unknown pools could outlast the 15 s shutdown sweep and hold back lanes on pools the projection already knew. The first fault now stops the reads, like `read_reanchor_batch`, and the known pools' lanes go on to the submit. A lane whose pool stays unknown (the read faulted, was cut short, or the pool is absent or `Closed`) now counts on its own `redemption_skipped_pool_unresolved` counter instead of `redemption_skipped_insolvent`, so an RPC fault no longer reads as drained pools. An absent or `Closed` pool logs a `warn!` with its lane count. New tests cover the seeded-and-kept path for an open unknown pool and a fault that leaves known pools to redeem. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- The unbound-request gate now sits before the origin-only backend probe, so an unbound request costs no `HEAD` either, and it logs the throttled "no verified binding" warn the lane gate used to give (production always wires a pool view, so that warn was unreachable). Both sites share `warn_unbound_request`. - `read_authorization` takes its `folded_at_read` baseline after it holds a read slot, so a redemption folded during the slot wait is not counted twice into a registered read that never goes stale. - A read that finds no slot counts on the new `decdn_serve_admit_read_slot_timeouts_total`, so a busy node is told apart from pools that fail to resolve. - The rate-limited debug line names the peer and its IP. - Docs give the real over-count bound of the mid-stream signer check (up to the read's `spent`), the read cap on `ResolvingPoolView`, and how a seeded pool's per-signer fold counts. New tests: a signer confirm that finds no slot is refused uncached and counted; two peers on one IP share the serve limiter's per-IP bucket. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Bucket refresh asked each bucket's most-recently-seen entry with no bond check, so a bonded-only table could still dial an entry that unbonded since it entered. `all_non_empty_picks` now aims at the most-recently-seen bonded entry and skips a bucket that holds none. Docs: the routing module, `insert`, `closest` / `closest_unbounded`, the FindValue responder and `note_peer_seen` now say which reads are filtered and that production writes go through `insert_active`; ADR 022 qualifies when a cooling peer leaves the table and lists the limiter layers in the order they are charged. New tests: the refresh pick skips unbonded entries; `insert_active` refreshes only bonded entries; bootstrap refuses an unbonded id a responder names. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- The admin RPC's `Origin` refusal returns a text body that says why, so it reads apart from a host-filter refusal; the admin test checks it. - The shared limiter docs list the serve limiter, the PromQL regex covers `serve`, and the module states the cost of narrowest-first ordering (a globally refused request still touches its keyed buckets). - The rate-limit config docs (`[dht.rate_limit]`, `[probe.rate_limit]`, `[serve.rate_limit]`, `RateLimitConfig`) say a `0.0` rate disables a layer whatever its burst, and that the resolver rejects a nonzero rate with a zero burst. - ADR 005 § Request rate limiting no longer says every refusal signs, and reads in active voice; the observability appendix counts three trios. - CHANGELOG: the limiter-order entry names only the limiters that shipped with the old order; the #2694 entry and #2701 title are corrected. - Runtime comments name the serve limiter's GC and the pool-only re-check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Note on the Review follow-ups pushed:
|
|
The |

What
Batch fix for the seven open
kind:security+area:nodeissues from the internal audit. Each issue is one commit with its own regression test. Two more commits fix findings an automated security review raised on the new code.Closes #2701
Closes #2711
Closes #2692
Closes #2690
Closes #2708
Closes #2694
Closes #2706
register_laneResolvingPoolView::signer_spent_cachedanswers from the cached admitgetAuthorizationread plus the fold since (spent + folded_since), the number admission already uses. It falls back to the projection only with no registered read. The error runs high by at most the read'sspent, so a stream near the cap can stop early but never over-delivers.resolve_unknown_poolsreads each pool the projection does not hold (onegetPool, 8 at a time) and seeds it. Lanes on absent,Closed, past-deadline or unreadable pools stay out of the submit. A failed read is a chain fault.HostFilterLayer(127.0.0.1:*,localhost:*) plus a layer that answers403to any request carryingOrigin; batches are disabled.RoutingTable::insert_activerefuses unbonded peers, and every production write uses it.closest_active[_unbounded]serves FindNode/FindValue answers, lookup seeds and republish fan-out. A full bucket evicts an unbonded or dial-cooling entry first.cdn/client/v1limiter[serve.rate_limit]three-layer limiter (per-peer 100/400, per-IP 200/800, global 2000/5000), checked per stream before the request is read. A refused stream gets an unsignedRATE_LIMITEDreset and counts ondecdn_serve_rate_limit_rejected_*_total.NotFoundbefore any chain read. AdmissiongetPool/getAuthorizationshare 16 node-wide slots.ThreeLayerRateLimiternow charges per-peer → per-IP → global, so a request a keyed layer refuses spends no global token. One floodingNodeIdcan no longer starve everyone else. This applies to the probe, DHT and serve limiters, and ADR 005 / ADR 022 now state the order.Breaking
[serve.rate_limit]section. It is optional; the defaults apply when it is absent.rejected_per_peer/rejected_per_ip, not onrejected_global.Hostnames. It refuses any request with anOriginheader, and it refuses batches.decdn node …, the dashboard and SSH tunnels keep working.Reviewer notes
Connectionsto ping with.PoolClosedrevert decoding. After the pre-submit resolve, every submitted pool is known, and the watcher folds its close events, so the revert case no longer arises.Unfundedrefusal (cli: a fetch with a drained capability retries until its timeout instead of failing #2338) needsgetAuthorization. Bound requests are bounded by the limiter and the read slots instead.[serve.rate_limit]defaults were not checked against live testnet stream rates. They are sized against the 100-streams-per-connection cap. A node pulling on a miss shares oneNodeIdacross all its pulls, so watchdecdn_serve_rate_limit_rejected_per_peer_totalafter deploy.decdn/devops. The threedecdn_serve_rate_limit_rejected_*_totalcounters are newINBOUND_FAILURE_REASONS, so the "Unattributed stream failures" panels and the alert rows need them.Verification
pre-commit run --all-files: every hook passed.cargo denyreports the existing crypto-bigint advisory, which is non-blocking.cargo clippy --workspace --all-targets --all-features -- -D warnings: clean.CARGO_BUILD_WARNINGS=deny cargo doc --workspace --no-deps --document-private-items: clean.cargo nextest run --workspace: 6101 passed, none skipped.cargo nextest run -p decdn-e2e --features anvil-e2e: 113 passed.anvil_settlement_e2e,anvil_bringup_shutdown_e2e): passed.adr/:make -C adr check-refspassed, and theadr/architecture.mdthreat table is updated.adr/appendix-observability.md. The devops dashboards are the follow-up above.CHANGELOG.md: one Security entry per fix.🤖 Generated with Claude Code