Bounty
XE-0447 · Bounty

[Medium] api: clientIP trusts X-Forwarded-For on loopback — a direct client chooses its own rate-limit bucket per request (inverse of #168, default deployment, no --ui needed)

Closed · duplicate —claimed Medium xe#255 filed 2026-11-04 09:24 UTC by Fahri Raditya Arrifudin

Report

Suggested severity: Medium

Duplicate check: swept the full live tracker. #168 covers the UI-proxy direction of the same helper (Go's proxy appends 127.0.0.1, so all UI clients collapse into one bucket) and is explicitly scoped to --ui traffic. #172 covers the 100 k-entry limiter-map hard-fail. This report claims the inverse direction, which neither covers: a direct client of the default API deployment chooses its own rate-limit bucket per request. Not re-claiming #172's map-overflow defect.

Reviewed at commit 02e9641b0ac64437f57e09d63301f88cce61a802.

Root cause

api/handler.go:375-393 (clientIP):

if !isLoopbackHost(host) { return host }
if xff := r.Header.Get("X-Forwarded-For"); xff != "" {
    if last := strings.TrimSpace(parts[len(parts)-1]); last != "" { return last }  // attacker-chosen
}

The API default-binds 127.0.0.1 (cmd/xe/main.go:1292), so every direct client is loopback and every client chooses its own bucket. rateLimitMiddleware (:364-373) keys every limiter on clientIP(r).

Observed (PoC against a copy of the repo)

POST /blocks/send x120 with rotating X-Forwarded-For: accepted=120 rate-limited=0
POST /blocks/send x120 with NO X-Forwarded-For:        accepted=50  rate-limited=70
500 GETs with 500 distinct XFF values all served

The write limiter (burst 50) is fully bypassed by rotating one header value.

Impact

  • Every per-IP rate limit in the API — block submission, attestation, chat, directory — is bypassable by any client that can reach the API port, in the default deployment (no --ui, no proxy required). This is a strictly larger attack surface than #168's UI-proxy scope.
  • The same helper keys the timekeeper attestation limit (node/attestation.go:86-105) on the forgeable string, which interacts with #236 — noted there as a comment rather than re-claimed here.

Fix direction: trust X-Forwarded-For only when the listener is explicitly configured behind a proxy (--api-trusted-proxy); otherwise use RemoteAddr.

Thread

Joseph Denneteam2026-11-05 22:08 UTCgithub

Thanks. This is the same finding as https://bounty.xe.network/XE-0082, which was filed first; the programme pays the first verifiable submission, so this one closes as a duplicate. If you believe it is a different bug, reply with what differs and we will look again.