<!-- XE-0099 · Loopback XFF trust collapses all UI-proxy clients into one limiter bucket · testnet -->
*Markdown view of <https://bounty.xe.network/XE-0099>. The page is the record; this is the same page for reading.*

XE-0099 · Bounty

# Loopback XFF trust collapses all UI-proxy clients into one limiter bucket

Closed · duplicate
—claimed Medium
[xe#168](https://github.com/xeprotocol/xe/issues/168)
filed 2026-10-29 04:35 UTC
by 0xMissy22

Verdict
:   Duplicate

Tier
:   —

Claimed
:   Medium

Area
:   —

Duplicate of
:   [XE-0082](https://bounty.xe.network/XE-0082) awarded

Tracked
:   —

Updated
:   2026-11-10 00:11 UTC

Told
:   2026-11-05 22:08 UTC

### Patches

- [xe#187](https://github.com/xeprotocol/xe/pull/187) open by arturbarszcz78
  fix(api): walk XFF backwards skipping loopback to preserve client IP (fixes #168)

### History

- [9342](https://bounty.xe.network/log/9342) 2026-11-05 22:08 UTC github.state\_pushed
- [9341](https://bounty.xe.network/log/9341) 2026-11-05 22:08 UTC github.labels
- [9339](https://bounty.xe.network/log/9339) 2026-11-05 22:08 UTC reply.mirrored
- [9313](https://bounty.xe.network/log/9313) 2026-11-05 22:08 UTC reply.sent
- [9312](https://bounty.xe.network/log/9312) 2026-11-05 22:08 UTC proposal.adopted
- [9311](https://bounty.xe.network/log/9311) 2026-11-05 22:08 UTC proposal.adopted
- [9310](https://bounty.xe.network/log/9310) 2026-11-05 22:08 UTC ticket.status new → closed
- [9309](https://bounty.xe.network/log/9309) 2026-11-05 22:08 UTC proposal.adopted
- [9308](https://bounty.xe.network/log/9308) 2026-11-05 22:08 UTC ticket.facts
- [9307](https://bounty.xe.network/log/9307) 2026-11-05 22:08 UTC proposal.adopted
- [9306](https://bounty.xe.network/log/9306) 2026-11-05 22:08 UTC ticket.facts
- [7888](https://bounty.xe.network/log/7888) 2026-11-05 14:02 UTC proposal.created

[Full history](https://bounty.xe.network/log?ref=XE-0099) · [JSON](https://bounty.xe.network/v1/tickets/XE-0099) · [markdown](https://bounty.xe.network/XE-0099.md)

### Report

# Loopback XFF trust collapses all UI-proxy clients into one limiter bucket

## Summary

The UI proxies `/api/*` to the API on loopback, and the API's `clientIP`
trusts `X-Forwarded-For` on loopback connections, taking the last XFF
element. Go's reverse proxy appends its bare loopback IP to the header, so
every UI API request lands in the same rate-limiter bucket: one heavy UI
user exhausting the shared read burst (1000, then 200/s) or write burst
(50, then 10/s) gets 429s for all UI users.

## Impact

API availability for UI users. One UI client can deny the API to every
other UI client through the shared bucket; no funds are directly at
stake, and direct non-loopback connections correctly ignore XFF, so this
is scoped to UI-proxied traffic. The 429 consequence was proven at the
limiter level (see Proof of concept), not just inferred from bucket-key
equality.

Suggested program tier: **Medium**.

## Root cause

- `cmd/xe/main.go:1509-1514` \+ `api/ui.go:34-44` (Director plus the
  `/api/` mount): the UI reverse-proxies API requests to
  `http://127.0.0.1:<apiPort>`. The default `--api-bind` is already
  `127.0.0.1`, so the loopback target holds by default, not only via the
  wildcard normalization. The UI path requires `--ui` (default off).
- `api/handler.go:375-393` `clientIP` (with `isLoopbackHost` at `:395-400`):
  on a loopback `RemoteAddr` it returns the last comma-separated XFF
  element verbatim — no port stripping, no normalization — falling back
  to `X-Real-IP` and then the host. Direct non-loopback connections
  return the host early and ignore XFF entirely.
- `api/handler.go:364-372` `rateLimitMiddleware` keys the limiter by
  `clientIP(r)` and returns 429 `rate limit exceeded` on exhaustion.
  Constants (`handler.go:296-297`): read 200/s with burst 1000, write
  10/s with burst 50\.
- Why the bucket is shared: Go's proxy appends its bare loopback IP, so
  the backend sees `X-Forwarded-For: 9.9.9.9, 127.0.0.1` and the last
  element — the key — is `127.0.0.1` for every UI client. An earlier
  draft of this report claimed the proxy appends IP:port (a fresh bucket
  per connection); the harness disproved that and proved the opposite,
  and this report states the correction plainly.
- Generalization, no scope change: the collapse holds for any fixed proxy
  IP, not just loopback — with a non-loopback proxy address, clients
  still collapse to one key (the proxy's IP), because non-loopback
  `RemoteAddr` is returned verbatim.

## Proof of concept

Target: `xeprotocol/xe` @ `978785929bc17a2f4ab30c383e5fc9cf4d634512`
(2026-10-15). Two harnesses, both against the real `api` package; the
repository itself is not modified.

Attached PoCs: `pocs/slice8-harness.t.txt` (original harness, 6 tests)
and `pocs/reval-f06-test.go.txt` (re-validation harness, including the
end-to-end 429 test), both byte-identical copies of the runnable
sources.

Run (Go 1.25.14):

```
export PATH="$HOME/.local/go/bin:$PATH"
GOPROXY=off go test ./api/ -run 'TestSlice8' -count=5 -vet=off -v
```

Observed output (verbatim, re-validation run 2026-10-29): all 6 tests
PASS on all 5 runs, zero failures. Every iteration of the proxy test
logged:

```
request 0: backend XFF="9.9.9.9, 127.0.0.1" -> clientIP bucket key="127.0.0.1"
request 1: backend XFF="9.9.9.9, 127.0.0.1" -> clientIP bucket key="127.0.0.1"
```

### End-to-end 429 proof (re-validation 2026-10-29)

A second test wired the real `NewUIHandler` through the real
`rateLimitMiddleware` with the real limiter configuration (not a lowered
one) over real HTTP through two test servers. Client A (XFF `1.1.1.1`)
through the UI proxy was allowed 1387 requests (burst 1000 plus 200/s
refill during the \~1.9 s drain) before the shared bucket 429'd; client B
(XFF `2.2.2.2`) through the same UI proxy then got 429\. A control on
the same middleware instance — a fresh non-loopback key — got 200,
proving the 429 is bucket-keyed, not a global lockout.

No escape was found: `clientIP` has only two callers in the repository
(`rateLimitMiddleware` and attestation); IPv6 loopback `[::1]` and the
`localhost` hostname are both treated as loopback; a trailing-comma XFF
with an empty last element falls back to the host bucket `127.0.0.1` —
still the shared bucket; and X-Real-IP cannot override XFF when both are
present.

## Reproduction steps

1. Two fresh connections through the UI proxy to the API.
2. Observe both bucketed under `127.0.0.1`.
3. Exhaust the shared burst from one → all UI users get 429\.

## Recommended fix

Key UI-proxied requests by an authenticated/session identifier, or stop
trusting XFF on loopback, or exempt the UI proxy path from the shared
bucket.

## Severity

- CVSS 3.1: 5.3 — `CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L`
- CWE-400 (Uncontrolled Resource Consumption)

## Caveats

- The 429 proof is a loopback end-to-end run through the real middleware
  stack, not a production deployment observation.
- The conditional variant — fresh-bucket minting if a front proxy
  forwards client headers without appending its own bare IP — is NOT part
  of this claim: the front-proxy layout of the public deployment was not
  tested and no deployment configuration for it exists in the repository.
- No XE-specific prior report of the limiter/XFF mechanism was found
  (dedup query Q6 recorded in the audit's DEDUP-BASELINE.md; only generic
  XFF articles recurred).
- This reproduction runs against the repository code at the stated HEAD. No
  testnet transactions were sent as part of this report.

Payout address (XE): eff2c51dd8457df740b919226cd9b37a2944e5abea7501094db80234f87f010e

Best,
Chaplin

[slice8-harness.t.txt](https://github.com/user-attachments/files/34112467/slice8-harness.t.txt)
[reval-f06-test.go.txt](https://github.com/user-attachments/files/34112468/reval-f06-test.go.txt)

### Thread

**Joseph Denne**team2026-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.
