Skip to content

Support for X-Forwarded-Host header #5940

Closed

Description

@pedro-tramontin

Title: Support for X-Forwarded-Host header

Description:
Today envoy does not seem to forward the original host in a X-Forwarded-Host header, it just rewrites the original one and apparently there is no way to get the original host back again.
I found a reference for this header in the source code but it seems it is not being used anywhere else: (

const LowerCaseString ForwardedHost{"x-forwarded-host"};
)

Activity

  1. added
    enhancement
    help wanted
    on Feb 13, 2019
  2. pedro-tramontin commented on Mar 15, 2019

    @pedro-tramontin
    Author

    Hello, I would like to try to add this feature and need some guidance.
    Does it make sense to check for the options host_rewrite and auto_host_rewrite and copy the original host to X-Forwarded-Host header when the change is about to happen?
    Should there be any configuration that enable/disable this header?

  3. mattklein123 commented on Mar 15, 2019

    @mattklein123
    Member

    @pedro-tramontin SGTM. I'm not sure if we want to config guard it or not. On one hand, I think it would be OK to not config guard if we only set when a host mutation happens as you point out. On the other hand, it's possible that upstreams are not expecting us to set it and we might break them. @envoyproxy/maintainers any thoughts?

  4. yanniszark commented on Feb 22, 2020

    @yanniszark

    Hi all!
    This is a feature we (Arrikto) would like to have in Envoy, as it's something we rely upon to build correct URLs even with multiple proxies in the request's journey.

    I am really unfamiliar with advanced C++ code, but I read through the docs and tried to take a stab at it.

    According to MDN's definition for X-Forwarded-For:

    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.

    A simple example to illustrate:

    
     +----------+
     |          |
     |   App    |
     |          |
     +----------+
          ^ Host: app.namespace.svc.cluster.local
          | X-Forwarded-Host: example.com
     +----------+
     |          |
     |  Envoy   |
     |          |
     +----------+
          ^
          | Host:example.com
          |
          |
         User
    
    

    So the algorithm for this functionality is:

    If request host/authority is changed when the request is proxied, set x-forwarded-host to old x-forwarded host + old host:
    x-forwarded-host = append(x-forwarded-host, host)

    After reading through the Envoy architecture, I see that HTTP Connection Manager converts bytes to HTTP and passes traffic through an HTTP Filter Chain.
    The Router HTTP Filter should be the one responsible for making the decision to change a request's host/authority, so I am looking into it.

    After reading the architecture documents and comparing it with the code structure, I was very happy to find out that things were very nicely organized (kudos to maintainers) and I managed to make some progress.

    In particular, this part seems interesting:

    const auto parsed_authority =

    What I plan to do is:

    1. Parse request's host/authority.
    2. Get corresponding cluster for route.
    3. Get cluster's hostname.
    4. If cluster's hostname is different from request's host/authority, add the x-forwarded-for header.

    @pedro-tramontin @mattklein123 any tips / directions would be highly welcome.
    This is very new territory for me 😄

  5. mattklein123 commented on Feb 23, 2020

    @mattklein123
    Member

    IMO we don't need to do any parsing here as we pass through the host unchanged in almost all cases. We only need to (optionally) set the header when we do one of the header mutation functions?

  6. lambdai commented on Apr 12, 2021

    @lambdai
    Contributor

    @pedro-tramontin (since you are assigned) and @arun-vasudev (since you are the author of the latest PR) Are you still working on this?
    Any update?

  7. arun-vasudev commented on Apr 15, 2021

    @arun-vasudev
    Contributor

    I will address the review comments and upload a new patch by April 18. @lambdai. I had lost track of this!

  8. blained3 commented on May 5, 2021

    @blained3

    @arun-vasudev Has the patch been released?

  9. tbarrella commented on May 21, 2021

    @tbarrella
    Contributor

    Hi @arun-vasudev, do you still intend to work on this?

  10. arun-vasudev commented on May 26, 2021

    @arun-vasudev
    Contributor

    Hi @tbarrella, I will send out the new patch in a day or so. Was busy at work.

  11. Ido-Itz commented on Jul 29, 2021

    @Ido-Itz

    Hi folks. I was wondering if this is still planned. Any new updates on this topic?
    Really looking forward to this feature

  12. arun-vasudev commented on Oct 14, 2021

    @arun-vasudev
    Contributor

    I am working on it again!

  13. added a commit that references this issue on Nov 23, 2021
    91c2e6b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancementhelp wanted

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions