Skip to content

cdn/dht/v1 DoS hardening — per-publisher quota, DHT rate limit, lookup invariants #625

Closed

Description

@alpergundogdu

Context

ADR 022's threat model addresses prefetch-poisoning Sybil attacks but does not cover the broader permissionless surface on cdn/dht/v1. STORE is gated by active-staker membership (#431), but FIND_VALUE / FIND_NODE are unauthenticated beyond QUIC NodeId, and the DHT ALPN inherits no rate limit from ADR 005's probe-only token bucket. Reputation is local-EWMA-only today (gossip aggregation deferred per ADR 008 §14a), so the "false STORE → reputation penalty" mitigation has receiver-local blast radius, not the network-wide hit ADR 022 implies.

These gaps are not addressed by #320's wire-type and handler scope. This issue captures the hardening work needed alongside the base implementation.

Scope

Per-publisher STORE quota (handler)

ADR 022 caps stored records at 100k/node but specifies no eviction policy and no per-publisher quota. A single staker can flood a receiver's table; if eviction is global LRU, attacker churn evicts legitimate records on demand.

  • Add max_records_per_publisher config (recommended default: 200).
  • Eviction is per-publisher LRU, not global LRU. Publisher A flooding cannot evict publisher B's records.
  • Reject STORE with StoreAck { accepted: false } once a publisher's quota is full.
  • Requires ADR 022 text update in § Content Records and TTL.

Three-layer DHT rate limit (handler)

Mirror ADR 005's probe rate-limit machinery onto cdn/dht/v1:

Layer Recommended default Source
Per-peer (NodeId) 20 req/sec QUIC connection NodeId
Per-IP 100 req/sec Source IP
Global 1000 req/sec All inbound DHT traffic

Apply before any routing-table lookup or response serialization. Failed admission closes the stream with RATE_LIMITED per ADR 013. Cheapest-first ordering (global → per-IP → per-peer), matching the probe limiter. Requires ADR 022 to gain a new § DHT Rate Limiting section symmetric to ADR 005's.

Requester-side lookup invariants (handler)

Pure-defense changes that don't touch wire format but ADR 022 does not currently specify:

  • XOR-distance invariant. Requester MUST reject any closer_nodes entry from a responder whose XOR distance to the target is not strictly less than the responder's own.
  • Requester-side provider randomization. Move randomization off the responder. Requester MUST shuffle FindValueResponse.providers before probing. Closes the modified-responder selection-bias gap that ADR 022 explicitly acknowledges as unenforceable.
  • Active-staker sanity filter. Requester filters returned providers against its cached active-staker set before probing, silently dropping non-stakers.

Negative probe cache (handler)

ADR 001 has a 15-second positive probe cache. Add the symmetric negative cache — (NodeId, hash) → has_blob: false with 5-minute TTL, max 1024 entries — so K-closest false-STORE publishers aren't re-probed on every cache miss inside the window. Closes the probe-budget-exhaustion attack where false STOREs at K-closest nodes drain a victim's outbound probe rate.

Mechanics live in ADR 001 (symmetric to its existing positive cache). ADR 022 § FIND_VALUE Flow and § Threat model cross-reference the negative cache as the load-bearing mitigation for K-closest false STORE.

Re-publish jitter + K+overflow (handler)

ADR 022 publishes at deterministic T + 45min to exactly K=20 closest peers. Predictable timing plus minimum-cardinality target set make a 15-minute targeted DoS sufficient to expire records, dropping the blob to the on-chain directory fallback.

  • Jitter: randomize next re-publish to T + uniform(30min, 50min) per record.
  • Overflow: publish STORE to K+3 closest peers. Receivers at the overflow positions accept or reject by their own routing-table policy.
  • Requires ADR 022 text update in § STORE Flow.

Out of scope

  • NodeId grinding mitigation. ADR 019's ed25519 signature proves NodeId control but not origin — operator picks the keypair freely. Constraining NodeId to hash(operator_address, registrationNonce) would close grinding but touches ADR 003 (NodeId-to-Ethereum binding) and ADR 019 (registration signature). Needs its own ADR amendment.
  • Holdings/hash enumeration privacy. Inherent property of any global content-discovery layer; aligns with ADR 005's stance that probe responses are public information. Belongs in an ADR 022 Consequences update, not here.
  • Active-staker cache event subscription. The event-subscription pattern (NodeRegistered, NodeDeregistered, NodeAutoEjected) is already established in ADR 019. The DHT handler should consume the same cache. Folds into Implement content discovery via cdn/dht/v1 Kademlia DHT #320, not a separate concern.

Acceptance criteria

  1. A single staked publisher cannot exceed max_records_per_publisher records at any receiver; eviction is per-publisher LRU.
  2. cdn/dht/v1 inbound traffic is bounded by global / per-IP / per-peer token buckets; rejections emit a metric labeled by layer (matches decdn_probe_rate_limit_rejections_total shape).
  3. A responder returning closer_nodes containing entries not strictly closer than itself is rejected by the requester.
  4. FindValueResponse.providers is randomized requester-side before probing; tests assert order independence from responder.
  5. A NodeId that returned has_blob: false for hash H within the last 5 minutes is not re-probed for H during that window.
  6. Re-publish time per record is jittered uniformly in [T+30min, T+50min]; STORE targets are K+3 closest peers.

ADR updates required

  • Fix A (per-publisher quota): ADR 022 § Content Records and TTL — add per-publisher quota and per-publisher LRU eviction policy. Without this, the 100k-record cap is exploitable; this fix is also the load-bearing bound on STORE-flooding cost. Mention in § Threat model.
  • Fix B (DHT rate limit): ADR 022 — new § DHT Rate Limiting section symmetric to ADR 005's probe rate limiting. Highest-leverage hardening: caps the rate at which most other DHT attacks can be mounted. Mention in § Threat model.
  • Fix F (negative probe cache): ADR 001 § Probe cache — add the symmetric negative variant alongside the existing positive cache. ADR 022 § FIND_VALUE Flow + § Threat model cross-reference it as the mitigation for K-closest false STORE probe-budget exhaustion.
  • Fix G (re-publish jitter + K+overflow): ADR 022 § STORE Flow — randomize re-publish to [T+30, T+50] minutes, publish to K+3 closest peers. Closes the deterministic re-publish suppression window.
  • Fixes C, D (lookup invariants): ADR 022 § FIND_VALUE Flow — XOR-distance invariant on closer_nodes and requester-side providers randomization, both as MUSTs. C also strengthens against NodeId grinding's lookup-redirection variant.

A, B, F are the highest-compounding fixes (each touches multiple attacks; see issue thread for leverage matrix) and should be reflected explicitly in ADR 022's threat model so the rationale is preserved alongside the mechanics.

References

Activity

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

    @github-actions

    🎯 Triage report

    This issue identifies five concrete DoS hardening gaps in the cdn/dht/v1 handler that are not covered by the base DHT implementation in #320: per-publisher STORE quota with per-publisher LRU eviction, a three-layer rate limit mirroring ADR 005, requester-side lookup invariants (XOR-distance, provider randomization, active-staker filter), a negative probe cache closing probe-budget exhaustion, and re-publish jitter + K+3 overflow. Each scope item includes a specific ADR 022 section that must be updated. The issue is labeled poc-blocking, meaning all six acceptance criteria must be met before the PoC network launch.

    📊 Assessment

    Dimension Value Reasoning
    Type Task Well-scoped hardening work with explicit acceptance criteria; not a bug report or feature proposal
    Labels security, adr-review, high (added); technical, poc-blocking (existing) Security-class attack surface; ADR 022 requires four text updates; PoC-blocking priority warrants high
    Coding agent Needs more info The implementation scope is clear and acceptance criteria are precise, but the handler work is tightly coupled to #320 (which is still open) and requires ADR 022 to be updated in lockstep — a coding agent could tackle individual sub-tasks once #320 is merged and ADR 022 edits are co-located in the same PR

    🔗 Similar issues

    💡 Notes and suggestions

    Suggested implementation order (minimises re-work):

    1. Wait for Implement content discovery via cdn/dht/v1 Kademlia DHT #320 to merge. All five hardening items are handler-layer changes that sit on top of the wire types and routing-table primitives Implement content discovery via cdn/dht/v1 Kademlia DHT #320 delivers.
    2. ADR 022 text updates first. Make the four required ADR edits (§ Content Records and TTL, § STORE Flow, new § DHT Rate Limiting, § FIND_VALUE Flow) in one PR so implementation can reference normative text.
    3. Three-layer rate limit. The token-bucket machinery already exists for cdn/probe/v1 (ADR 005 / ConnectionLimiter). The DHT limiter is a parallel instantiation — copy the probe limiter pattern, wire it into cdn/dht/v1 before any routing-table access. Metric label shape should match decdn_probe_rate_limit_rejections_total.
    4. Per-publisher STORE quota. Add max_records_per_publisher: usize to the DHT handler config (default 200). Track HashMap<NodeId, VecDeque<RecordKey>> per publisher; on insertion, if len ≥ limit, evict the oldest entry for that publisher (per-publisher LRU), not the globally oldest.
    5. Negative probe cache. A HashMap<(NodeId, Hash), Instant> with a 5-min TTL and bounded at 1024 entries (evict by insertion order). Check before any outbound probe in the FIND_VALUE path.
    6. Requester-side invariants. XOR-distance check: on receiving closer_nodes, compute xor(node.id, target) and xor(responder.id, target); drop entries where xor(entry.id, target) >= xor(responder.id, target). Provider shuffle: call rand::seq::SliceRandom::shuffle on providers immediately after decode, before any probe. Active-staker filter: use the same cached set already consumed for STORE gating (docs(adr): pin cdn/dht/v1 stake check, provider ordering, and stream cap #431).
    7. Re-publish jitter + K+3. Replace T + 45min with T + rand::thread_rng().gen_range(30min..=50min). Change target peer count from K to K + 3.

    Testing notes:

    • Per-publisher quota test: send 201 STOREs from the same NodeId, assert 201st returns StoreAck { accepted: false }, assert a different publisher's records are unaffected.
    • Rate limit test: use permissive_limiter in tests not exercising rate-limit behaviour (per repo convention); add a dedicated test that saturates the per-peer bucket.
    • Negative cache test: assert that after a has_blob: false response, a second probe to the same (NodeId, hash) within 5 min is suppressed.
    • XOR-distance test: inject a crafted closer_nodes response containing an entry farther than the responder; assert it is silently dropped.
    • Jitter test: sample re-publish time over N iterations, assert all values fall in [30min, 50min].

    Generated by Agentic Triage for issue #625 · ● 2.9M · ◷

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/issue-triage.md@94ec5db57374c5b04a4b8eef8b4413f9af44d63f
    
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