Skip to content

DHT rate limiter: bound per-IP / per-peer keyed limiter keyspace #645

Closed

Description

@thiras

Context

PR #643 added the three-layer cdn/dht/v1 rate limiter (per-peer NodeId, per-IP, global) per ADR 022 §DHT Rate Limiting. The per-IP and per-peer layers use governor::DefaultKeyedRateLimiter with no keyspace cap or pruning — an attacker churning many source IPs and/or many authenticated NodeIds can grow the keyed map without bound, same DoS shape that #440 fixed for the connection-level dispatch limiter.

Scope

Mirror the dispatch::ConnectionLimiter pattern at `crates/node/src/dispatch.rs`:

  • Add max_tracked_* knobs to DhtRateLimitConfig (per-IP and per-peer).
  • Resolve them via [dht] config (defaults consistent with the existing security.max_tracked_sources = 4096).
  • Lazy prune inside check() when the keyspace exceeds cap + cap/10, single-flighted via pruning_in_progress: AtomicBool + PruneGuard (already-modeled pattern).
  • Periodic GC task driven by the runtime, same governor::retain_recent call as ConnectionLimiter::gc_per_source.
  • Metric counters for prune sweeps + tracked-set sizes.
  • Unit tests cover: bounded growth under flood, recovery after refill, layer-disable short-circuits.

Acceptance

  • Per-IP and per-peer keyspaces stay bounded under sustained-distinct-key load.
  • No regression in admission throughput on the happy path (the prune fires only over-cap).
  • decdn_dht_rate_limit_tracked_{per_ip,per_peer} gauges visible in the scrape.

Raised by PR #643 review feedback (Copilot, crates/node/src/dht/rate_limit.rs:120).
Related: #440 (the dispatch-limiter equivalent).

Activity

  1. self-assigned this
    on May 21, 2026
  2. added
    prio:high
    kind:security
    on May 21, 2026
  3. github-actions commented on May 21, 2026

    @github-actions

    🎯 Triage report

    An unbounded keyspace DoS vulnerability in the DHT rate limiter introduced by PR #643. An attacker churning distinct source IPs or NodeIds can grow governor::DefaultKeyedRateLimiter maps without limit, mirroring the exact shape fixed for the dispatch limiter in #440. The issue is well-specified with clear implementation scope (mirroring ConnectionLimiter) and concrete acceptance criteria.

    📊 Assessment

    Dimension Value Reasoning
    Type Task Implementation follow-up from a PR review; clear scope, no design ambiguity
    Labels security, technical, high Memory-exhaustion DoS via attacker-controlled input is a security concern; high priority given the gap was introduced in a recently merged PR
    Coding agent Suitable Requirements are fully specified: config knobs, lazy prune with cap + cap/10 threshold, AtomicBool single-flight guard, periodic GC task, metric gauges, and explicit unit test cases. Pattern already exists in crates/node/src/dispatch.rs to copy from.

    🔗 Similar issues

    💡 Notes and suggestions

    Implementation checklist (derived from scope):

    • Add max_tracked_ips: usize and max_tracked_peers: usize to DhtRateLimitConfig in crates/node/src/dht/rate_limit.rs; default both to 4096 to match security.max_tracked_sources
    • Wire defaults through [dht] config block in common config schema
    • In DhtRateLimiter::check(): after inserting a new key, compare keyspace len against cap + cap/10; if over, set pruning_in_progress and spawn a prune task (mirror ConnectionLimiter::maybe_prune)
    • Add PruneGuard RAII type (or reuse if extractable) to clear pruning_in_progress on drop
    • Add periodic GC task in node runtime wiring, calling governor::retain_recent on both keyed limiters (mirror ConnectionLimiter::gc_per_source)
    • Expose decdn_dht_rate_limit_tracked_per_ip and decdn_dht_rate_limit_tracked_per_peer gauge metrics; register in the existing metrics registry
    • Unit tests:
      • Flood with N > cap distinct keys → assert keyspace len ≤ cap + cap/10 + tolerance
      • Verify admission throughput unchanged when under-cap (no spurious prune)
      • Verify layer-disable short-circuit still works (no prune attempted when layer disabled)

    Key file: crates/node/src/dht/rate_limit.rs:120 (flagged in PR #643 review)
    Reference pattern: crates/node/src/dispatch.rs — ConnectionLimiter struct

    Anti-panic note: Remember the workspace-wide unwrap_used/expect_used/indexing_slicing deny — use .get() and Result/Option combinators throughout.

    Generated by Agentic Triage for issue #645 · ● 1.4M · ◷

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
  4. added a commit that references this issue on May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:securityprio:high

Type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions