Skip to content

node: DHT per-IP rate limiter keys on full IpAddr — IPv6 /64 rotation bypasses it (dispatch limiter already masks) #841

Closed

Description

@thiras

Surfaced by a full-repository review (2026-06-09).

Finding

The DHT per-IP rate-limit layer (crates/node/src/dht/rate_limit.rs:249-259) keys buckets on the full IpAddr. The dispatch limiter already solved this: source_key() in crates/node/src/dispatch.rs:60-71 masks IPv6 addresses to their /64 prefix.

Impact

An attacker with a customer-grade IPv6 /64 allocation has 2^64 distinct source addresses and defeats the per-IP DHT tier entirely by rotating — each request lands in a fresh bucket. The keyspace cap (max_tracked_per_ip + lazy prune, #645) bounds memory but not the rate-limit bypass. The per-peer (NodeId) and global layers still apply, but the per-IP tier is silently ineffective against IPv6 floods.

Fix

Apply the same /64 mask as dispatch.rs source_key() before check_key/contains in try_admit_one, and to the trusted_ips membership test. Consider extracting the mask helper so both limiters share it.

Refs

Activity

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

    @github-actions

    🎯 Triage report

    Security bug in crates/node/src/dht/rate_limit.rs where the per-IP DHT rate limiter keys on the full IpAddr. An attacker with a standard consumer /64 IPv6 allocation has 2^64 distinct addresses and can trivially rotate them to land each request in a fresh bucket, making the per-IP tier silently ineffective. The dispatch limiter already carries the correct fix (source_key() in dispatch.rs:60-71); this is purely a masking gap that was not carried across when the DHT limiter was implemented.

    📊 Assessment

    Dimension Value Reasoning
    Type Bug Existing mitigation is bypassed by a trivially accessible IPv6 rotation technique
    Labels bug, security, medium (already applied) Correct; the per-IP tier is defeated, but per-peer NodeId and global layers still apply
    Coding agent Suitable Exact file + line references, fix pattern already in codebase (dispatch.rs:source_key()), no design decisions required

    🔗 Similar issues

    💡 Notes and suggestions

    Fix checklist

    • Extract the IPv6 /64 masking logic from dispatch.rs:source_key() into a shared helper (e.g., fn mask_to_prefix(addr: IpAddr) -> IpAddr in crates/node/src/ or common) so both limiters share one implementation
    • Apply the masked key in dht/rate_limit.rs:249-259 (try_admit_one) before every check_key / contains call
    • Apply the same mask to the trusted_ips membership test in dht/rate_limit.rs so a trusted /64 match works correctly regardless of source address within the prefix
    • Add a unit test: send N > per_ip_burst requests from distinct addresses within the same /64, assert all are admitted up to limit and then rate-limited (proving the mask collapses them into one bucket)

    Scope note

    The fix is intentionally narrow — masking only; no changes to bucket state, eviction, or config schema. The /64 prefix mask is already the established codebase convention and matches [RFC 6177]((www.rfceditor.org/redacted) typical end-site allocation size. If in future the node is deployed in an environment where attacker-controlled /48s are realistic (e.g., transit providers), the mask prefix could be made a config knob, but that is out of scope here.

    Generated by Agentic Triage for issue #841 · sonnet46 578.3K · ◷

    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
  4. added 2 commits that reference this issue 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:medium

Type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions