Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

To identify a client behind a proxy safely, start with the IP address of the connection your application actually received, then trust forwarded IP headers only if that connection came through a proxy you control or explicitly trust. Never treat the leftmost X-Forwarded-For value—or any other header—as proof of a client’s identity.

Why the application may see a proxy IP

Your web server can observe the address of its immediate network peer: the system that connected directly to it. If a reverse proxy, load balancer, or content delivery network sits in front of the application, that peer address belongs to the intermediary, not necessarily to the original client. The proxy may pass client-origin information in HTTP headers, but those values are useful for security only when the application can establish that the request arrived through a trusted proxy path.

This distinction matters for rate limits, IP allowlists, authorization, fraud controls, and audit records. A header is request data, not identity verification. If an attacker can send a request directly to the application or supply a forged forwarding header, trusting the header can make those controls apply to an address chosen by the attacker.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What the forwarding headers tell you—and what they do not

X-Forwarded-For

X-Forwarded-For (XFF) is a widely used, de-facto header. It commonly contains a comma-separated sequence of addresses, with the originating address at the left and later proxies appended on the right. That ordering is a convention, not a guarantee that the first value is genuine: a client may supply a forged value unless trusted ingress and proxy behavior prevent it. See MDN’s X-Forwarded-For guidance.

#1 Best Overall
WatchGuard Firebox M295 High Availability Unit with 3 Year Standard Support - HA Device for Failover, Requires Matching Primary - Not a Standalone Device - Rackmount Firewall (WGM295000+WGM2951603)
  • High Availability (HA) redundant unit for resilient failover and uptime. Operates only as the secondary in an HA pair and must be paired with a primary WatchGuard Firebox of the same model for synchronization and failover. Not a standalone appliance.
  • WatchGuard Firebox M295 High Availability Unit with 3 Year Standard Support License (WGM29501603) - The Firebox M295 combines enterprise-grade security with multi-gig connectivity, SD-WAN, TLS decryption, and proxy-based inspection in a compact rackmount design.
  • Standard Support covers software updates and round-the-clock emergency help. Add a Basic or Total Security Suite to activate IPS, gateway antivirus, and web filtering so threats are blocked before they reach users.
  • Standard Support provides reliable technical assistance and software updates for WatchGuard Firebox appliances. Offering 24x7 help for emergencies and business-hours support for routine needs, it ensures your network stays secure and operational.
  • Interfaces and continuity: 4x 2.5Gb RJ45, 4x 1Gb RJ45, 2x 10Gb SFP+ with VLANs and link aggregation, plus RIP, OSPF, BGP, and high availability to keep sites online.

Forwarded

Forwarded is the standardized HTTP header defined by RFC 7239. It can include a for address, but standardization does not establish who supplied the value or whether it is trustworthy. Proxies can add, alter, or remove forwarding information, and use of this header does not remove the need to verify the network path. See MDN’s Forwarded reference.

Provider-specific headers

Headers from a particular CDN or proxy are not interchangeable with generic forwarding headers. For example, Cloudflare recommends CF-Connecting-IP or True-Client-IP for restoring the visitor IP at an origin. Use such a header only when the origin can verify that the request arrived through Cloudflare’s trusted path; otherwise a client might send the same header directly. Consult Cloudflare’s original visitor IP documentation for that provider-specific behavior.

Choose a trust model that matches your proxy topology

Two common approaches are to trust a defined set of proxy addresses or networks, or to trust a fixed number of proxy hops. Neither is safe if untrusted traffic can reach the application through a path that bypasses the expected proxies.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Approach When it fits What you must maintain Key failure mode
Trusted proxy addresses or networks Proxy membership or routes are managed and identifiable by IP addresses or CIDR ranges. Keep the trusted proxy list current as infrastructure changes. Frameworks may expose settings for known proxies or networks. An outdated or overly broad list can cause the application to trust headers from an unintended peer.
Trusted proxy count Every request follows a fixed, controlled number of proxy hops. Ensure the configured count matches the actual path for requests the application receives. Different routes or a topology change can make the count wrong, causing an untrusted address to be treated as trusted or vice versa.

Do not use a trust-all setting. Also restrict direct access to the application origin when your architecture permits it. MDN warns that if a server remains directly reachable from the internet, no part of the XFF list can be considered trustworthy or safe for security-related use—even when the server also sits behind a trusted reverse proxy. Read the full MDN X-Forwarded-For security guidance.

How to resolve a client address safely

  1. Map the request path. Identify each reverse proxy, load balancer, and CDN between public clients and the application. Determine whether any route lets clients reach the origin directly.
  2. Secure the ingress boundary. Where the design allows, limit origin access to the expected proxy path. If direct access remains possible, do not use the forwarded chain for security decisions.
  3. Configure explicit trust. In the framework or middleware, specify the trusted proxy IPs or networks, or a trusted count only if the topology is fixed and controlled. Avoid trusting forwarding headers from every peer.
  4. Anchor parsing to the actual peer. Treat the socket peer—the system that connected to the application—as the starting boundary. Do not choose the leftmost XFF entry just because it is often described as the client address.
  5. Walk the forwarded chain from right to left. Combine all XFF header fields, parse valid addresses, and move from the application-facing side while each address belongs to the configured trusted proxy set. The first address outside that set is the address suitable for security decisions. It may be an untrusted upstream intermediary rather than the end user.
  6. Apply provider-specific rules narrowly. If using a CDN’s client-IP header, follow that provider’s documented setup and accept it only on a verifiably trusted ingress path.
  7. Verify framework behavior. Header precedence and middleware behavior vary by framework and version. Use the official documentation for the deployed version rather than copying a setting or code sample from another stack.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Keep detection separate from enforcement and logging

Only a client address resolved through the trusted proxy boundary should inform security controls such as rate limits, allowlists, authorization, or fraud checks. An unverified forwarded value may be recorded as a diagnostic hint only if it is clearly labeled unverified; it should not be presented as an authenticated client address in audit records.

Framework configuration is part of the security boundary, not a substitute for network controls. ASP.NET Core documents configuration for known proxies and networks in its proxy and load balancer guidance. Keycloak likewise warns that spoofed proxy headers can affect access control and audit logs; see its reverse proxy documentation. Follow the instructions for the version and topology you actually deploy.

Handle client IPs as privacy-sensitive data

Client IP addresses can be privacy-sensitive. Collect them only for a defined operational purpose, restrict access to the records, and set retention limits appropriate to that purpose and your deployment’s obligations. The fact that a proxy makes an address available does not mean an application should retain it indefinitely. MDN discusses privacy considerations for X-Forwarded-For and Forwarded.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.