troubleshooting Networks
Trusted proxy chains and client IP attribution
A forwarded address is justified by a trusted chain, not by its position in a header. Follow the receiving peer and the right-to-left trust walk before attributing an address.
What it means
A forwarded client address is a claim until the receiving service knows which proxies are allowed to supply it. Start with the address of the immediate network peer, then apply an explicit trust policy to the addresses in the forwarded header. Do not select the first address merely because it appears first.
A reverse proxy commonly opens its own connection to an application. The application's socket peer is therefore the proxy, not necessarily the device that originally made the request. Forwarded metadata can help recover a meaningful address for the application, but the header itself is not proof of where the request originated. RFC 7239 discusses this trust problem for the standardized Forwarded field. NGINX's real-IP module illustrates one implementation policy: with recursive processing enabled and a trusted original peer, select the last non-trusted address from the supplied header.
The distinction matters for logs and access decisions. An address attributed at a trust boundary is not a verified identity of a person or device, and a valid-looking header is not a reason to grant access.
Try it
Simulation: the immediate peer is trusted, the supplied X-Forwarded-For list is 192.0.2.99, 192.0.2.10, 192.0.2.20, and the policy trusts 192.0.2.20. Inspect the result, then change only Trust for 192.0.2.20 to untrusted. Notice where the walk stops and which earlier claims are ignored. Use Reset to restore all five inputs.
Trusted proxy chains and client IP attribution
Recover a justified client address from forwarded headers under an explicit trusted-hop policy
The first non-trusted address from the right is the justified attribution boundary in this policy.
Trust walk
- Socket peertrusted
- 192.0.2.20Trusted — continue
- 192.0.2.10Attribution boundary
Result
- Attributed address192.0.2.10
- Ignored claims192.0.2.99
Read right to left through trusted claims. The boundary is an address attribution under the stipulated policy, not a person’s identity.
Evaluated inputs
- Required scenario evidence
- provided
- Immediate peer evidence
- trusted
- Header evidence
- XFF
- Synthetic X-Forwarded-For list
- 192.0.2.99, 192.0.2.10, 192.0.2.20
- Trust for 192.0.2.20
- trusted
Conservative teaching policy inspired by recursive nginx real-IP lookup, not exact nginx error handling. Only 1–8 documentation IPv4 literals from 192.0.2.0/24, no ports/IPv6/multiple header merging/Forwarded grammar, no actual request or identification of a person. Unknown never supplies an attributed IP.
About this model
The controls set only a local, bounded scenario. The computed branch is not a verdict about a live system. Inputs listed as not evaluated did not participate in this branch after validation.
Reset restores the original inputs. It does not change the open or closed state of help or FAQ answers.
The example is local and uses documentation addresses. It does not inspect a real request, determine the trust of a real proxy, or change a server. Do not enter actual user IP addresses, authorization headers, or other private request data.
Walk from the receiving side
Imagine a deployment where trusted proxies append the address of the peer from which each accepted the request. The application sees a socket peer at the receiving end and a list of claims carried with the request. The example stipulates that the receiving side has already established the trust status of that socket peer. It does not try to discover that status from the header.
In the default example, the rightmost listed address is the first address examined. The policy skips a listed address only when its trust is established. It stops at the first non-trusted address rather than continuing through claims whose provenance it cannot establish.
| Observation in order | Value | Interpretation |
|---|---|---|
| Immediate peer evidence | trusted | The policy may examine the supplied XFF list |
| Rightmost listed address | 192.0.2.20 | Trusted under the supplied rule; continue left |
| Next listed address | 192.0.2.10 | Non-trusted boundary; attribute this address |
| Earlier claim | 192.0.2.99 | Ignored for attribution |
This explains why the default result is 192.0.2.10, even though 192.0.2.99 appears first. The model accepts the first non-trusted hop as the boundary of the trusted chain, not as proof that no intermediary exists farther upstream.
What changes when the evidence changes?
Change the trust for 192.0.2.20 to untrusted. Now the first listed hop examined is already the boundary, so the model attributes 192.0.2.20 and ignores both addresses to its left. No address text changed; the justified inference changed because the trust policy changed.
Change the immediate peer to untrusted. The simulation reports the stipulated socket peer 192.0.2.90, not any address from the header. The forwarded claims are not evaluated. This remains true for a nonempty malformed list, because an untrusted peer does not gain authority from a header that happens to look well formed.
Restore the immediate peer to trusted, then set the list to just 192.0.2.20, with trust for that hop set to trusted. The walk exhausts the list without finding a non-trusted address. Under this deliberately conservative policy there is no justified forwarded attribution. Do not silently substitute the last trusted proxy as the originating client.
If the immediate peer's trust is unknown, or the required trust of the listed 192.0.2.20 is unknown, the model cannot attribute a forwarded IP. Likewise, an absent header, a Forwarded header instead of the supported XFF form, an out-of-range octet, a trailing empty list element, or a chain containing only a trusted listed hop yields unknown under the stipulated policy. Missing required scenario evidence stops the evaluation. A blank text control is an input error, not a remembered previous result.
In practice
Before using forwarded metadata in a real access decision, separate observations from assumptions. Identify the immediate peer from the actual connection. Determine which proxy addresses or ranges are explicitly trusted, which header is supported, and whether the authorized ingress path appends, replaces, or rejects client-supplied values. These choices must agree at the receiving service. A direct path to the application that bypasses the intended ingress changes the trust assumptions.
For an authorized NGINX deployment, check the installed version and the applicable documentation for set_real_ip_from, real_ip_header, and real_ip_recursive. The module's recursive selection rule is not a general grammar for every forwarding header. The model uses a deliberately conservative policy inspired by that rule: one to eight IPv4 literals from a documentation subnet, one named listed proxy whose trust can vary, and no handling of ports, IPv6, merged headers, or the RFC 7239 parameter syntax. Actual implementation-specific error handling can differ.
Stop: If you cannot establish the ingress path and header-handling policy, do not broaden the trusted address range or use an unverified forwarded value to authorize an action. Collect the missing evidence first. If an authorized configuration change is needed, preserve the existing configuration, test with a controlled synthetic request through the intended path and a non-trusted path, and verify the resulting observation before applying it more broadly. Revert to the preserved configuration if the observations disagree with the intended rule.
The useful conclusion is a boundary: when the trust walk stops, you have a justified address under that policy, not an authenticated user. If the boundary cannot be established, leave attribution unknown rather than choosing an attractive-looking entry in the list.
Frequently asked questions
Editorial questions based on the listed sources and explicitly labeled local examples.
Why not use the first address?
A sender can include an address claim before the trusted proxy appends its observation. Stop at the first non-trusted address walking from the receiving side; entries farther left have no established provenance.
Are Forwarded and X-Forwarded-For interchangeable?
No. RFC 7239 defines a parameterized Forwarded syntax. This example accepts only a restricted XFF-style list of IPv4 literals; do not parse Forwarded as that list.
What if the direct peer is not trusted?
Do not use the forwarded claim to replace the observed peer. The peer address is an observation of that connection, not proof of the originating device.
What if every listed hop is trusted?
In this conservative lab, exhausting the supported list without finding a non-trusted hop yields unknown forwarded attribution. An incomplete list or unknown trust is also insufficient. Real proxy software can define a different fallback; check the applicable policy.
Sources & model boundaries
Primary references used for this explanation. The interactive example is an educational model, not a live check.
- RFC 7239: Forwarded HTTP Extension
8.1. Forwarded can be forged or modified. Trust assumptions and privacy implications matter, not merely header presence.
Checked .
- NGINX ngx_http_realip_module
real_ip_recursive. When recursive real-IP processing and original-peer trust apply, NGINX uses the last non-trusted address. The lab uses a narrower teaching policy.
Checked .