Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

X-Forwarded-Host vs. x-Forwarded-Server

What is the difference between the following headers?

  • X-Forwarded-Host
  • X-Forwarded-Server

In a setup with Apache being the proxy and Tomcat the origin server I see both of them in the HTTP requests that reach Tomcat. Values were (this is from my own code logging the header name and value pairs with the actual capitalization I encountered)

x-forwarded-host some-server
x-forwarded-server some-server.dept.some-uni.edu

Are the above values typical? Which of the two should I use to reliably reconstruct the URL asked by the browser? In my case, the browser sent a GET with the some-server.dept.some-uni.edu value in the request URL which leads me to think that the x-forwarded-server is more relevant to reconstruct the URL. I find this somewhat at odds with the MDN documentation only mentioning X-Forwarded-Host and stating that this is the "de-facto standard header for identifying the original host requested by the client" (and containing no documentation on X-Forwarded-Server)

This Apache page OTOH describes both headers as follows:

  • X-Forwarded-Host The original host requested by the client in the Host HTTP request header.
  • X-Forwarded-Server The hostname of the proxy server.

(I appreciate that to reconstruct the URL I also need X-Forwarded-Proto and X-Forwarded-Port)

like image 253
Marcus Junius Brutus Avatar asked Apr 28 '17 22:04

Marcus Junius Brutus


People also ask

What is X-Forwarded host?

The X-Forwarded-Host (XFH) header is a de-facto standard header for identifying the original host requested by the client in the Host HTTP request header.

What is Proxy_set_header X-Forwarded-For?

Definition of Nginx X-Forwarded-For. Nginx x-forwarded-for header is the header of the de-facto standard used for identifying the client connecting originating IP address to web server through the proxy of HTTP or we can also connect through by using a load balancer.

Is X-Forwarded-For trustworthy?

If any trusted reverse proxies are between the client and server, the final X-Forwarded-For IP addresses (one for each trusted proxy) are trustworthy, as they were added by trusted proxies. (That's true as long as the server is only accessible through those proxies and not also directly).

What is X original host?

X-original-host header contains the original host header with which the request arrived. This header is useful in Azure website integration, where the incoming host header is modified before traffic is routed to the backend. If session affinity is enabled as an option, then it adds a gateway-managed affinity cookie.


1 Answers

Since there might be multiple proxies involved in resolving a connection the X-Forwarded-Host-Header is the one you should use in the service-application.

The header X-Forwarded-Server gets overwritten by each proxy, which is involved in the communication, with the current proxy's hostname.

like image 84
smoebody Avatar answered Sep 28 '22 09:09

smoebody