tomMoulard / htransformation

A Traefik plugin to change on the fly header's value of a request
MIT License
81 stars 13 forks source link

Rewrite host #35

Closed larsboldt closed 2 years ago

larsboldt commented 2 years ago

Why is X-Forwarded-Host changed when using Host instead of HTTP-Host?

- "traefik.http.middlewares.name.plugin.htransformation.Rules[0].Header=Host"
- "traefik.http.middlewares.name.plugin.htransformation.Rules[0].Type=RewriteValueRule"
tomMoulard commented 2 years ago

Hello @larsboldt,

Thanks for your interest in this Traefik plugin!

In your case, the plugin does not modify the X-Forwarded-Host header. It might be changed by traefik itself, or by another component in your stack, because the Host header is used when defining the X-Forwarded-Host header.

larsboldt commented 2 years ago

I am a bit confused as to how this works - I am using v2.9.1 of Traefik with only your plugin 0.2.6 and through docker. I have only default configuration and a router label with a HostRegexp to catch the incoming request.

If I use the URL http://test.localhost.192.168.68.102.traefik.me/ with the following configuration

- "traefik.http.routers.foo.middlewares=foo_htransformation,testHeader"
- "traefik.http.middlewares.testHeader.headers.customrequestheaders.Host=foo.localhost.bar"
- "traefik.http.middlewares.foo_htransformation.plugin.htransformation.Rules[0].Header=Host"
- "traefik.http.middlewares.foo_htransformation.plugin.htransformation.Rules[0].Type=RewriteValueRule"
- "traefik.http.middlewares.foo_htransformation.plugin.htransformation.Rules[0].Value=^(.*?)localhost"
- "traefik.http.middlewares.foo_htransformation.plugin.htransformation.Rules[0].ValueReplace=$$1localhost"

I would expect the header Host to be test.localhost and X-Forwarded-Host to be test.localhost.192.168.68.102.traefik.me. Yet with your explanation, if X-Forwarded-Host is based on Host, X-Forwarded-Host should be foo.localhost? But it is not. The result is that the Host is foo.localhost.bar and X-Forwarded-Host is test.localhost.

So built-in middleware seems to change the host header, but your plugin does not, and the result is an unexpercted change to X-Forwarded-Host.

Does this not seem off to you?