{"id":"XE-0082","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"81","source_url":"https://github.com/xeprotocol/xe/issues/81","reporter_id":25,"title":"api/ui: UI reverse proxy makes clientIP resolve to 127.0.0.1, so all web wallet/explorer traffic shares one rate-limit bucket (High)","area":"node-api","claimed_tier":"high","assessed_tier":"high","verdict":"valid","duplicate_of":null,"tracked":true,"internal_ref":"#1047","internal_url":"https://github.com/xeprotocol/core/issues/1047","status":"awarded","closed_reason":null,"github_state":"open","disclosed_at":null,"award_xe":2000000000,"award_approved":true,"paid_ref":"","created_at":"2026-10-29T13:57:23.710842+00:00","updated_at":"2026-11-05T22:09:15.864788+00:00","source_created_at":"2026-10-26T20:48:38+00:00","told_at":null,"status_changed_at":"2026-11-05T22:08:36.929353+00:00","url":"https://bounty.xe.network/XE-0082","body":"- Suggested tier: High (\"rate limit abuse that degrades service for other clients\", \"degradation one client can cause\")\n- Area: `api/ui.go` UI reverse proxy, `api/handler.go` `clientIP` and rate limiter, testnet deployment\n- Found: 2026-10-26, repo master `9787859`\n\n**Note:** this is a code-analysis finding. I have not run any load against the public nodes. The behaviour below is read from the source and already observed (as a symptom) by the deployment docs. Confirming the user-facing impact would need a bounded measurement, and per the programme rules I would open a volume-test notice issue before running one.\n\n## Summary\n\nThe UI listener (`ldn.test.network`, wallet and explorer) proxies `/api/*` to the node API on `127.0.0.1:8080` with `httputil.NewSingleHostReverseProxy` and a custom `Director` (`api/ui.go:28`). With a `Director`, Go's `ReverseProxy` appends the immediate client address to `X-Forwarded-For`. The immediate client of the UI listener is the front proxy (Caddy) on loopback, so the API receives:\n\n```\nX-Forwarded-For: <real client IP>, 127.0.0.1\nRemoteAddr:      127.0.0.1:<port>   (the UI proxy)\n```\n\n`clientIP` (`api/handler.go:375`) trusts `X-Forwarded-For` only from loopback and takes the **last** entry:\n\n```go\nif !isLoopbackHost(host) {\n    return host\n}\nif xff := r.Header.Get(\"X-Forwarded-For\"); xff != \"\" {\n    parts := strings.Split(xff, \",\")\n    if last := strings.TrimSpace(parts[len(parts)-1]); last != \"\" {\n        return last\n    }\n}\n```\n\nThe last entry is always `127.0.0.1`, so every request that comes through the wallet or explorer is rate limited under the single key `127.0.0.1`: one shared bucket of read 200/s burst 1000, write 10/s burst 50, probe 20/s burst 100 (`api/handler.go:296`) for all users worldwide.\n\nThe deployment docs already observe the symptom without treating it as a defect: \"Because external clients behind Caddy share an egress bucket in the node's per-IP rate limiter, a plain sequential sweep of the public URLs can trip `429`\" (https://test.network/docs/deployment, Data Directory section above).\n\n## Impact (expected, to be measured)\n\n- One client sending about 51 POSTs in 5 seconds through `https://ldn.test.network/api/...` (even invalid ones, the limiter runs before validation) should make every other wallet user's send, receive and faucet related API calls fail with 429 for as long as it continues.\n- Reads: about 1000 requests in 5 seconds should do the same for the explorer and wallet balance views.\n- The cost to the attacker is tiny (no PoW, no funds, no signature), well inside what one home connection can do.\n\n## How to confirm (not done yet)\n\nNeeds a short, bounded measurement and, per the programme rules, a notice issue first:\n\n1. From IP A, send 60 POST requests with an empty JSON body to `https://ldn.test.network/api/blocks/send` within 2 seconds, once. Expect 429 after about 50.\n2. During those seconds, from a different IP B (for example a phone on mobile data), request the same URL once. If B also gets 429, the bucket is shared.\n3. Stop. Total: about 61 requests.\n\n## Suggested fix\n\n- In the UI proxy, use `Rewrite` with `pr.SetXForwarded()` or copy the incoming `X-Forwarded-For` unchanged, so the real client stays last.\n- Or have `clientIP` walk `X-Forwarded-For` from the right and skip trusted proxy addresses (loopback), returning the first untrusted one.\n\n## Payout\n\nXE address: `6591eab453dbd93b27e2cd674712f94b42d9e7e4d52980b966fa6da4ccd832dc` (same as #75).\n","patch_refs":[{"id":137,"repo":"xeprotocol/xe","kind":"pr","ref":"117","title":"fix(api): resolve clientIP across reverse proxy chain to prevent shared rate limit bucket (#81)","url":"https://github.com/xeprotocol/xe/pull/117","note":"","state":"open","author":"arturbarszcz78","added_by":"desk","created_at":"2026-10-29T13:57:30.091343+00:00"},{"id":225,"repo":"xeprotocol/core","kind":"pr","ref":"1108","title":"","url":"https://github.com/xeprotocol/core/pull/1108","note":"","state":"","author":"","added_by":"token:4","created_at":"2026-10-30T14:20:23.339713+00:00"}],"thread":[{"id":31,"source":"github","source_ref":"6464089414","author":"arturbarszcz78","team":false,"body":"[comment from a blocked account removed]","created_at":"2026-10-28T08:16:41+00:00"}]}