{"id":"XE-0447","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"255","source_url":"https://github.com/xeprotocol/xe/issues/255","reporter_id":190,"title":"[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)","area":null,"claimed_tier":"medium","assessed_tier":null,"verdict":"duplicate","duplicate_of":"XE-0082","tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"closed","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-04T09:26:12.734279+00:00","updated_at":"2026-11-10T00:11:30.382229+00:00","source_created_at":"2026-11-04T09:24:32+00:00","told_at":"2026-11-05T22:08:15+00:00","status_changed_at":"2026-11-05T22:08:11.344127+00:00","url":"https://bounty.xe.network/XE-0447","body":"**Suggested severity: Medium**\n\n**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.\n\nReviewed at commit `02e9641b0ac64437f57e09d63301f88cce61a802`.\n\n## Root cause\n`api/handler.go:375-393` (`clientIP`):\n```go\nif !isLoopbackHost(host) { return host }\nif xff := r.Header.Get(\"X-Forwarded-For\"); xff != \"\" {\n    if last := strings.TrimSpace(parts[len(parts)-1]); last != \"\" { return last }  // attacker-chosen\n}\n```\nThe 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)`.\n\n## Observed (PoC against a copy of the repo)\n```\nPOST /blocks/send x120 with rotating X-Forwarded-For: accepted=120 rate-limited=0\nPOST /blocks/send x120 with NO X-Forwarded-For:        accepted=50  rate-limited=70\n500 GETs with 500 distinct XFF values all served\n```\nThe write limiter (burst 50) is fully bypassed by rotating one header value.\n\n## Impact\n- 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.\n- 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.\n\n**Fix direction:** trust `X-Forwarded-For` only when the listener is explicitly configured behind a proxy (`--api-trusted-proxy`); otherwise use `RemoteAddr`.\n","patch_refs":[{"id":272,"repo":"xeprotocol/xe","kind":"pr","ref":"264","title":"fix(api): ignore forwarded headers on direct loopback requests unless trusted proxy configured (fixes #255)","url":"https://github.com/xeprotocol/xe/pull/264","note":"","state":"open","author":"tipprb","added_by":"desk","created_at":"2026-11-04T10:33:57.594471+00:00"}],"thread":[{"id":402,"source":"github","source_ref":"6670810813","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as https://bounty.xe.network/XE-0082, which was filed first; the programme pays the\nfirst verifiable submission, so this one closes as a duplicate. If you believe it is a different\nbug, reply with what differs and we will look again.","created_at":"2026-11-05T22:08:15+00:00"}]}