Case review: every visitor looked internal until we configured trusted proxies
After site analytics went live, client IP and region detection depended on X-Forwarded-For from the reverse proxy. Without declared trusted proxies, the server either saw only the proxy's internal address or could be misled by client-forged headers. The fix was to trust only addresses added by our own proxy and canary one instance first.
This review is based on a recent real SalpX operations event, with server addresses, internal ranges, ports, people and deployment identifiers removed.
Symptom
After site analytics was enabled, the health check raised two warnings: trusted proxy not configured and region database not configured. Until fixed, visitor IP and region dimensions could not be treated as reliable even though events were being stored.
Investigation
- Confirm the request path. Public requests reach a reverse proxy first, which forwards them to app instances. The TCP peer the app sees is the proxy's internal address, not the visitor's.
- Confirm where the real address comes from. The proxy appends the client address it sees to
X-Forwarded-For(XFF). To get the visitor IP, the app has to read this header.
- Confirm the risk. XFF is an ordinary request header, and clients can send a forged value. If the app does not separate "added by the proxy" from "sent by the client", analytics and any IP-based decision can be polluted.
Root cause
MDN is direct: only when every proxy in the chain is trusted and correctly configured can the parts added by those proxies be trusted, and if the server can be reached directly from the internet, no part of XFF can be used for security-related purposes. Any security use of XFF, such as rate limiting or IP-based access control, must only use addresses added by a trusted proxy.1
There are two selection methods: configure a trusted proxy count, or a trusted proxy list, then scan right to left skipping trusted proxies; the first address not on the list is the target.1 The app had no trusted proxy list, so it could not safely take the visitor address from XFF.
Fix
- Declare trusted proxies. Configure the container network range hosting the reverse proxy as trusted. A range rather than a single address is used because the proxy container's address can change on rebuild, and a single address would silently stop matching.
- Mount an offline region database. Region lookup uses offline database files, mounted read-only into the app with no external lookup service. The database format must match the lookup API the app uses (this time, separate IPv4 and IPv6 files were required).
- Canary one instance first. Apply the configuration to the standby instance, confirm it is healthy, send a real request to verify that XFF stripping and region lookup both work, and only then roll the primary.
- Clean up verification data. Test requests carry a dedicated marker and are deleted by that marker afterward, without touching real visitor data.
After the fix, both health warnings cleared, and region and source attribution in analytics returned to normal.
Lessons
- For an app behind a reverse proxy, the IP it sees is the proxy's by default. Visitor addresses require reading XFF, and reading XFF requires configuring trusted proxies.
- Base the trusted range on networks you control: it survives container rebuilds without treating public addresses as trusted proxies.
- Treat analytics and security uses separately: MDN notes that leftmost untrusted values must only be used where spoofing has no negative impact.1
Checklist
- List every proxy hop on the request path and confirm which you control.
- Configure trusted proxies explicitly in the app (count or list); never just take the first XFF value.
- App instances should not be reachable from the internet bypassing the proxy; otherwise XFF as a whole is untrustworthy.1
- Test with a forged XFF: the address the app identifies should still be the real one added by the proxy.
- Mount the region database read-only and record its version and checksum.
- Canary configuration changes on one instance before rolling the rest.
In one line
Only the part of X-Forwarded-For written by your own proxy is trustworthy. Declare trusted proxies before relying on visitor IPs and regions.
Sources & attribution
This article references the public materials listed below. Analysis and wording are SalpX's own; quoted material remains the property of its original authors and publishers.
- X-Forwarded-For header - HTTP — MDN Web Docs · accessed 2026-11-28Note:MDN: XFF can be spoofed; security uses must only rely on addresses added by trusted proxies, selected right-to-left by trusted proxy count or list.
One key for Claude, GPT and 50+ models
The SalpX gateway is OpenAI-SDK compatible. Point base_url at https://www.salpx.com/v1 and you are done.