Forwarded

Robotecture » HTTP » HTTP Headers » Forwarded

Forwarded HTTP Header: What You Need to Know

The Forwarded HTTP Header is an important component of the HTTP protocol. It provides information about the client-facing side of proxy servers, which is altered or lost during the request’s path through the proxy. The Forwarded Header is used to provide information to the server about the originating client’s IP address, as well as those of the intermediaries that the HTTP request passed through.

HTTP headers allow the client and the server to pass additional information with an HTTP request or response. The Forwarded Header consists of key=value pairs separated by a semicolon. The directives include by=<identifier>, for=<identifier>, host=<host>, and proto=<http|https>. If there are multiple proxy servers between the client and server, they may each specify their own forwarding information.

The Forwarded Header is used for debugging, statistics, and generating location-dependent content. It is also used by load balancers, reverse proxies, and other network devices to forward traffic to the appropriate server. Spoofing the Forwarded Header is a common tactic used by attackers to bypass security measures, which is why it is important to validate the header before processing it.

What Is the Forwarded HTTP Header?

The Forwarded HTTP header is a request header that is used to identify the originating IP address of a client when the client is communicating with a server through one or more proxy servers or load balancers. It is used to pass information about the client’s IP address and other request properties to the server.

HTTP headers are used to pass additional information between the client and the server with an HTTP request or response. They consist of a case-insensitive name followed by a colon and then by their value. Whitespace before the value is ignored. There are two types of headers: request headers and response headers.

The Forwarded HTTP header is a request header that is used to inform the server about the originating client’s IP address, as well as the addresses of intermediaries that the HTTP request has passed through. Examples of intermediaries might be forward or reverse proxy servers, a load balancer, or a content delivery network (CDN).

The Forwarded HTTP header is used to replace the traditional non-standard headers like X-Forwarded-For, X-Forwarded-Proto, and X-Forwarded-Host which were used to inform the upstream server about the user’s IP address and other request properties.

The following table shows some of the common fields that can be found in the Forwarded HTTP header:

Field NameDescription
byThe address of the entity that forwarded the message
forThe address of the client that initiated the request
hostThe host name and port number of the server to which the request was sent
protoThe protocol used to transmit the message
proto-versionThe version of the protocol used to transmit the message

Components of the Forwarded HTTP Header

The Forwarded HTTP header is a widely used HTTP header that contains information about the client-facing side of proxy servers. It is used to provide information that is altered or lost when a proxy is involved in the path of the request. This section will discuss the two main components of the Forwarded HTTP header: IP Addresses and Directives.

IP Addresses

The Forwarded HTTP header contains information about the IP addresses of the client and the proxy servers that the request has passed through. This information is essential for servers to identify the source of the request accurately. The following IP address formats are used in the Forwarded HTTP header:

  • IPv4: This is a 32-bit address that is used to identify devices on a network. It is written in the form of four numbers separated by dots (e.g., 192.168.0.1).
  • IPv6: This is a 128-bit address that is used to identify devices on a network. It is written in the form of eight groups of four hexadecimal digits separated by colons (e.g., 2001:0db8:85a3:0000:0000:8a2e:0370:7334).

How to Set Forwarded HTTP Header

Setting a Forwarded HTTP Header is an important step in ensuring that requests are properly handled by proxy servers. Here are some examples of how to set a Forwarded HTTP Header:

Examples

Example 1: Using Nginx

One way to set a Forwarded HTTP Header is by using Nginx. To do this, you can add the following lines to your Nginx configuration file:

proxy_set_header Forwarded "by=$proxy_protocol";

This will set the Forwarded header to include the protocol used by the proxy server.

Example 2: Using Apache

Another way to set a Forwarded HTTP Header is by using Apache. To do this, you can add the following lines to your Apache configuration file:

RequestHeader set Forwarded "by=%{REMOTE_ADDR}e";

This will set the Forwarded header to include the IP address of the client.

Example 3: Using Node.js

If you are using Node.js, you can set the Forwarded header by using the forwarded module. To do this, you can add the following lines to your Node.js application:

const forwarded = require('forwarded');
const request = require('request');

const req = request.get('http://example.com');
req.setHeader('Forwarded', forwarded(req.headers).toString());

This will set the Forwarded header to include the IP address of the client and the protocol used by the proxy server.

Potential Issues and Pitfalls with Forwarded HTTP Header

In our journey to understand the vast landscape of HTTP headers, it’s crucial not to overlook potential issues and pitfalls that may accompany them. The Forwarded HTTP header is no exception. Like a double-edged sword, while it presents valuable client information, it can also introduce complexities and potential security risks.

Data Reliability

One of the significant issues with the Forwarded HTTP header lies in the reliability of its data. Because this header can be modified by any proxy involved in the request, the data it carries, such as the client’s IP address, could be altered. This could lead to incorrect or misleading information.

For instance, think of the Forwarded HTTP header as a game of ‘Chinese Whispers.’ If there’s a long chain of proxies, each adding their information to the Forwarded header, the information might be distorted by the time it reaches its final destination.

Privacy Concerns

The Forwarded HTTP header also raises privacy concerns. By revealing client information such as IP addresses and hostnames, it may inadvertently breach the privacy of the users. It’s like leaving digital footprints on a sandy beach; anyone with access to the Forwarded header can trace back to you.

Header Spoofing

Another serious pitfall is the risk of header spoofing. Malicious users can manipulate the Forwarded HTTP header to inject false information, potentially leading to security vulnerabilities. To give you an analogy, this is like a wolf in sheep’s clothing, where the wolf is the malicious user who manipulates the Forwarded header to appear as an innocent client.

Mitigating The Risks

Despite these issues, there are ways to mitigate the risks associated with the Forwarded HTTP header. For example, a server can be configured to trust the Forwarded HTTP header only from known and reliable proxies. Similarly, privacy concerns can be addressed by anonymizing certain parts of the Forwarded header information.

Other Proxy HTTP Headers

X-Forwarded-For

X-Forwarded-Host

X-Forwarded-Proto

Via