X-Forwarded-For

An HTTP header that identifies the original client IP address when traffic passes through proxies or load balancers.

The X-Forwarded-For (XFF) header is an HTTP request header used to identify the originating IP address of a client connecting to a web server through an intermediary proxy server, load balancer, or content delivery network (CDN).

How X-Forwarded-For Works

In standard HTTP communications, when a client directly accesses a server, the server logs the client's direct IP address. However, in modern network infrastructures, traffic frequently passes through various proxies, firewalls, and load balancers designed for performance, scalability, or enhanced security.

Without XFF, the web server would only record the IP address of the immediate proxy, thereby masking the true client origin. The X-Forwarded-For header mitigates this obscurity by appending the original client's IP address to the request.

Header Format

When multiple proxies are involved, XFF includes a comma-separated list of IP addresses showing the full path the request traversed:

X-Forwarded-For: client_ip, proxy1_ip, proxy2_ip

The leftmost IP address represents the original client, with subsequent addresses indicating each proxy in the chain.

Security Applications

Proper implementation of X-Forwarded-For is essential for robust cybersecurity practices:

  • Logging and auditing: Enables accurate recording of client origins for compliance and forensic investigations
  • Threat detection: Helps identify suspicious or malicious traffic sources
  • Access control: Allows implementation of IP-based restrictions and geolocation policies
  • Rate limiting: Enables proper throttling based on actual client IPs rather than proxy addresses

Security Considerations

Since the X-Forwarded-For header can be easily spoofed by malicious actors, servers should only trust XFF values from known, trusted proxies. Many organizations configure their systems to validate and sanitize these headers before using them for security decisions.