Bounty
XE-0112 · Bounty

api: rate-limiter map hits maxRateLimiterIPs, then every NEW client IP is denied by a permanent 0/0 limiter (Medium, measured)

Triaging xe#172 filed 2026-10-29 06:01 UTC by nexastark

Report

HTTP API rate-limiter map hits maxRateLimiterIPs, then every NEW client IP is denied by a permanent 0/0 limiter

Component: api/handler.go — ipRateLimiter.getLimiter Severity (my assessment): Medium — availability only, no funds or consensus impact Track: Volume & resilience → "Starvation: so many connections to chat or the API that other users can't get through" and "Resource exhaustion: load that runs a node out of memory"

Summary

ipRateLimiter.getLimiter keys buckets by the string returned from clientIP(r). When the map reaches maxRateLimiterIPs (100,000) it returns a brand-new limiter with rate 0 and burst 0 instead of evicting anything:

func (rl *ipRateLimiter) getLimiter(ip string) *rate.Limiter {
    rl.mu.Lock()
    defer rl.mu.Unlock()
    e, ok := rl.entries[ip]
    if !ok {
        if len(rl.entries) >= maxRateLimiterIPs {
            return rate.NewLimiter(0, 0)      // permanent deny for this IP
        }
        e = &rateLimiterEntry{limiter: rate.NewLimiter(rl.rate, rl.burst)}
        rl.entries[ip] = e
    }
    e.lastSeen = time.Now()
    return e.limiter
}

The only eviction is sweepLoop, which drops entries idle for rateLimiterTTL (5 minutes). There is no LRU and no limit on how fast the map can be filled.

Why it is reachable

clientIP trusts X-Forwarded-For whenever RemoteAddr is loopback (api/handler.go:380-388). That is the normal deployment shape: the embedded UI reverse proxy (api/ui.go, httputil.NewSingleHostReverseProxy) reaches the API over loopback, and an operator running the API with -api-bind 0.0.0.0 exposes it directly. In either case the bucket key is attacker-chosen.

Measured (local node built from this repo, xe node -api-port 18080)

Step RSS FD Threads
baseline 67,212 kB 14 11
300 heavy reads 67,212 kB 14 11
500 raw TCP held open 67,664 kB 514 11
40 SSE held (admin-gated → 403) 67,928 kB 54 11
20,000 distinct XFF IPs 150,152 kB 14 11
+80,000 more distinct XFF IPs 156,796 kB 14 11

≈ 4.2 kB RSS per spoofed IP; reaching the 100,000-entry cliff costs roughly 420 MB and takes about a minute at the measured ~1,900 req/s.

Once the cliff is reached (reproduced):

  • brand-new IP → 429 on every request (5/5)
  • previously-seen IP → 200 on every request (5/5)

The attacker, whose IPs are already in the map, keeps full access while every genuine new client is denied — a selective denial of service, not merely a slowdown.

Honest limits on this report

  • The public testnet API currently ignores XFF (its RemoteAddr is non-loopback), so the spoofing precondition does not hold for ldn.core.test.network as deployed today: 150 requests with one spoofed XFF all returned 200 because the real client IP was used. This is a code defect whose live exploitability depends on the operator's bind/proxy configuration, and I am not claiming otherwise.
  • No funds, consensus, finality or ledger state is affected.

Measured clean (no finding)

  • Slowloris does not work. 200 silent TCP connections were reaped exactly at the 10-second ReadHeaderTimeout (FD 214 → 14).
  • Read endpoints do not grow memory. 300 heavy reads left RSS unchanged.
  • No cross-endpoint starvation. 8 concurrent threads on /blocks/recent (p50 3.01s) left /health at p50 0.57s.

Not a duplicate

  • #81 / #117 / #168 are the opposite failure: clientIP collapses all clients into one shared bucket. This is the map growing to a hard cap after which new IPs get a 0/0 limiter. Different mechanism, different impact, different fix.
  • #137 adds per-IP limiting + LRU eviction to peerRateLimiter in net/ratelimit.go (libp2p path). This is api/handler.go (HTTP path), which still has FIFO-only sweeping and the 0/0 cliff.
  • #139 (open, unmerged) caps concurrent chat SSE per IP — unrelated to this map.
  • #67 is SSH-gateway connection slots.

Suggested direction

Bound the map with an LRU (as #137 did for the P2P limiter) so filling it evicts the least-recently-used bucket instead of denying every new IP; and/or only trust X-Forwarded-For when the immediate hop is a configured trusted proxy.

Reproduction

xe node -api-port 18080 -api-bind 127.0.0.1 -data ./data

# fill the map (distinct XFF per request; trusted because RemoteAddr is loopback)
for n in $(seq 0 99999); do
  curl -s -o /dev/null -H "X-Forwarded-For: 10.$((n/65536)).$(((n/256)%256)).$((n%256))" \
    http://127.0.0.1:18080/health
done

# brand-new IP is denied; an IP already in the map still works
curl -s -o /dev/null -w '%{http_code}\n' -H 'X-Forwarded-For: 198.51.100.7' http://127.0.0.1:18080/health   # 429
curl -s -o /dev/null -w '%{http_code}\n' -H 'X-Forwarded-For: 10.0.0.0'        http://127.0.0.1:18080/health   # 200

Measurement scripts and raw output: ~/bb-work/xe/nodetest/resource_measure.py, ~/bb-work/xe/nodetest/fill_ratelimit.py, resource_results.json, fill_ratelimit.log.

Campaign pre-notice: #170. Results will also be posted there.

XE address for reward: 425701cced5161806191f9421921766d9590523a2d595df32cb5367dc4477b41 Disclosure credit: Nexa Stark

Thread

Joseph Denneteam2026-11-08 20:18 UTCgithub

Thank you for the report and the measurements. We have confirmed the behaviour you describe and it is being handled; we will update this ticket as the fix progresses.