Skip to content

rate-limit: the two RateLimitConfig locals in runtime bring-up are swappable and untested #1463

Closed

Description

@yigitdot

Follow-up spotted while reviewing #1462 (which closed #1457 for the From<&Resolved*> for RateLimitConfig impls). Same failure class, one layer up.

The gap

#1457 covered the Resolved* -> RateLimitConfig mapping. Those From call sites are themselves safe by construction — RateLimitConfig::from(&cfg.probe) and ::from(&cfg.dht) take distinct types, so the type system picks the impl and a swap there cannot compile.

The next step is not protected. In crates/node/src/runtime/mod.rs:

let probe_rate_limit_cfg = RateLimitConfig::from(&cfg.probe);          // :857
let probe_rate_limiter = Arc::new(ProbeRateLimiter::new(&probe_rate_limit_cfg, ...));  // :858
...
let dht_rate_limit_cfg = RateLimitConfig::from(&cfg.dht);             // :902
let dht_rate_limiter = Arc::new(DhtRateLimiter::new(&dht_rate_limit_cfg, ...));        // :903

ProbeRateLimiter and DhtRateLimiter are distinct newtypes over ThreeLayerRateLimiter, but both constructors take &RateLimitConfig. The two locals are therefore interchangeable: passing dht_rate_limit_cfg to ProbeRateLimiter::new compiles clean, and nothing catches it. The declarations sit ~45 lines apart, so proximity does not help review either.

Why it matters

The two paths have deliberately different defaults, and the probe side is the tighter one (ADR 005 vs ADR 022):

per-peer per-IP
probe (ResolvedProbe::default) 5.0 req/s, burst 5 50.0 req/s, burst 200
DHT (ResolvedDht::default) 20.0 req/s, burst 40 100.0 req/s, burst 200

Feeding the probe limiter the DHT config silently loosens the per-peer probe cap 4x and the per-IP cap 2x on an unauthenticated path — the same category of quiet security regression #1457 was filed about, just at the wiring layer instead of the mapping layer.

Suggested fix

The From-impl approach does not transfer directly, since here the source type is the same on both sides. Options, roughly in increasing order of cost:

  1. Make the constructors take their own newtype (ProbeRateLimitConfig / DhtRateLimitConfig) so the compiler picks the pairing — turns this into an arity/type problem, matching how the From call sites are already safe.
  2. Have ProbeRateLimiter::new / DhtRateLimiter::new take the &Resolved* directly and do the From internally, removing the intermediate locals entirely.
  3. A bring-up test that asserts each limiter reports its own ADR defaults — weaker, since it pins observable behavior rather than preventing the swap.

Option 1 or 2 would let the *_mapping_is_not_transposed tests stay as the transposition guard and hand this layer back to the compiler.

Notes

Not urgent — no known miswiring today; both locals are correct on main. Filed separately rather than folded into #1462 because it touches runtime wiring and possibly the limiter constructor signatures, neither of which is in that PR's diff.

Activity

  1. added
    kind:security
    prio:medium
    rust
    kind:test
    on Jul 25, 2026
  2. self-assigned this
    on Jul 26, 2026
  3. thiras commented on Jul 26, 2026

    @thiras
    Contributor

    Already resolved on main by #1462 (519fba2f), which took Option 2 from this issue: ProbeRateLimiter::new / DhtRateLimiter::new gained from_resolved constructors that take &ResolvedProbe / &ResolvedDht and do the From internally, and runtime bring-up now calls those.

    The two swappable locals this issue describes are gone:

    // crates/node/src/runtime/mod.rs:858, :898
    let probe_rate_limiter = Arc::new(ProbeRateLimiter::from_resolved(&cfg.probe, ...));
    let dht_rate_limiter   = Arc::new(DhtRateLimiter::from_resolved(&cfg.dht, ...));

    Feeding the probe limiter the DHT config is now a type error rather than a silent 4x loosening of the per-peer probe cap. The only remaining RateLimitConfig::from(...) call sites in crates/node/src are inside the two from_resolved bodies (where the source type picks the impl) and in tests. Both constructors carry doc comments describing exactly the swap this issue was filed about — crates/node/src/handlers/probe_rate_limit.rs:91-105 and crates/node/src/dht/rate_limit.rs:86-101 — and the *_mapping_is_not_transposed tests remain the guard one layer down.

    Verified while batching #1466 / #1464 / #1459 in #1469.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind:securitykind:testprio: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