Skip to content

Instantly share code, notes, and snippets.

@richdougherty
Last active March 10, 2021 09:29
Show Gist options
  • Save richdougherty/ff00424178b9e1dba9bca65db9997146 to your computer and use it in GitHub Desktop.
Save richdougherty/ff00424178b9e1dba9bca65db9997146 to your computer and use it in GitHub Desktop.

Forwarding headers

  • X-Forwarded-For, X-Forwarded-Prot, X-Forwarded-Host, X-Forwarded-Port
  • Forwarded (params: for, by, proto)
  • Via
  • X-Real-IP

Docs

HTTP Proxies

CloudFront

http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/RequestAndResponseBehaviorCustomOrigin.html

  • X-Forwarded-For: appends
  • X-Forwarded-Proto: stripped

Elastic Load Balancer

For TCP load balancing, client address is preserved so no headers are modified. For application-level load balancing, headers are added.

Classic Load Balancer

http://docs.aws.amazon.com/elasticloadbalancing/latest/classic/x-forwarded-headers.html

  • X-Forwarded: appends
  • X-Forwarded-Proto: add or append (unclear)
  • X-Forwarded-Port: add or append (unclear)

Application Load Balancer

https://forums.aws.amazon.com/thread.jspa?messageID=738145

Application Load Balancer does pass "x-forwarded-for/x-forwarded-proto/x-forwarded-port" information with the request.

nghttpx

https://nghttp2.org/documentation/nghttpx.1.html

Highly configurable.

  • X-Forwarded-For: append, strip or ignore (obfuscated by default)
  • X-Forwarded-Proto: add or append (unclear) (obfuscated by default)
  • Forwarded: append, strip, etc (obfuscated)
  • Via: append, ignore, etc

Nginx

http://nginx.org/en/docs/http/ngx_http_realip_module.html

  • X-Forwarded-For: append, replace, rewrite with trusted, etc
  • X-Real-IP: ???

F5

CloudFlare

Apache

https://httpd.apache.org/docs/2.4/mod/mod_proxy.html

  • X-Forwarded-For: append
  • X-Forwarded-Host: append
  • X-Forwarded-Proto: append

Google Cloud Load Balancing

https://cloud.google.com/compute/docs/load-balancing/http/

  • Via: add or append (unclear)
  • X-Forwarded-Proto: set (probably doesn't append)
  • X-Forwarded-For: appends

Azure Application Gateway

No header modifications?

HAProxy

Header

Adds new X-Forwarded-For header to the end of the first request. Need to tell it to close the connection to the backend server on every request to force the header into every request. Doesn't add X-Forwarded-Proto, etc unless set manually, e.g. http-request add-header X-Forwarded-Proto https if { ssl_fc }.

Proxy protocol

The problem appears when haproxy runs with keep-alive on the side towards the client. The Stunnel patch will only add the X-Forwarded-For header to the first request of each connection and all subsequent requests will not have it. One solution could be to improve the patch to make it support keep-alive and parse all forwarded data, whether they're announced with a Content-Length or with a Transfer-Encoding, taking care of special methods such as HEAD which announce data without transfering them, etc... In fact, it would require implementing a full HTTP stack in Stunnel. It would then become a lot more complex, a lot less reliable and would not anymore be the "dumb proxy" that fits every purposes.

Headers

HTTP Servers

Play Framework

https://www.playframework.com/documentation/2.5.x/HTTPServer#Configuring-trusted-proxies

Django

https://docs.djangoproject.com/en/1.8/ref/settings/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment