<!-- XE-0447 · [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) · testnet -->
*Markdown view of <https://bounty.xe.network/XE-0447>. The page is the record; this is the same page for reading.*

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](https://github.com/xeprotocol/xe/issues/255)
filed 2026-11-04 09:24 UTC
by Fahri Raditya Arrifudin

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#264](https://github.com/xeprotocol/xe/pull/264) open by tipprb
  fix(api): ignore forwarded headers on direct loopback requests unless trusted proxy configured (fixes #255)

### History

- [9344](https://bounty.xe.network/log/9344) 2026-11-05 22:08 UTC github.state\_pushed
- [9343](https://bounty.xe.network/log/9343) 2026-11-05 22:08 UTC github.labels
- [9340](https://bounty.xe.network/log/9340) 2026-11-05 22:08 UTC reply.mirrored
- [9329](https://bounty.xe.network/log/9329) 2026-11-05 22:08 UTC reply.sent
- [9328](https://bounty.xe.network/log/9328) 2026-11-05 22:08 UTC proposal.adopted
- [9327](https://bounty.xe.network/log/9327) 2026-11-05 22:08 UTC proposal.adopted
- [9326](https://bounty.xe.network/log/9326) 2026-11-05 22:08 UTC ticket.status triaging → closed
- [9325](https://bounty.xe.network/log/9325) 2026-11-05 22:08 UTC proposal.adopted
- [9324](https://bounty.xe.network/log/9324) 2026-11-05 22:08 UTC ticket.facts
- [9323](https://bounty.xe.network/log/9323) 2026-11-05 22:08 UTC proposal.adopted
- [9322](https://bounty.xe.network/log/9322) 2026-11-05 22:08 UTC ticket.facts
- [7893](https://bounty.xe.network/log/7893) 2026-11-05 14:02 UTC proposal.created

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

### 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 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.
