-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
caddyhttp: support X-Forwarded-Host #3616
Conversation
cdb23ac
to
5d8cd0d
Compare
I'll be honest, I have concerns about this from a security standpoint. That header isn't necessarily safe to trust, any client could send it. This would add some implicit behaviour that not all users would clearly understand is happening. I think your approach with checking the header with a matcher in the issue you opened is more correct if your intention is specifically to trust that the Proxies should pass through the header with the actual |
Thanks for the PR! But I'm not sure I understand... why can't you do this:
I'm not convinced that folding Host and X-Forwarded-For together is a good, universally-non-breaking idea... do you have any evidence that this will not break any other configs that rely on Host or authority headers? |
@francislavoie in terms of a security standpoint, the in my use case, caddy is behind a gateway. from the gateway, the |
thinking more about the security implications, this PR could plug a security hole down the proxy chain. say the web server is PHP and blindly uses the request host to generate email links like password reset. if an attacker sends Host: app.com with X-Forwarded-Host: attack.com, caddy currently wouldn't validate the forwarded host header and the web server would send the link with the attack.com domain. regardless, that is not caddy's issue since caddy doesn't use host headers to generate any user consumed output. |
@mholt you're absolutely right. that work around is effective. I've no proof either, as I was hoping a caddy dev who knew more about the rest of the code might have an idea. or even replace my PR (since I'm not too experienced with golang) I feel the use case is common enough. say caddy is behind a load balancer, or API gateway, or anything that uses forwarded headers -- you would need this workaround. the expectation I had was that caddy's native address matcher would match the intended request host anywhere down the line. the question is whether caddy should support the forwarded header standard. |
The Host header and X-Forwarded-Host headers have different purposes. I think if you want to match on the X-Forwarded-Host header you should just do that, rather than us rolling them into one. I'm just not convinced that's a good idea (and there's a total lack of evidence here, the only argument is "it's what I expected to happen" but I'm not convinced that's a technically sound expectation). |
Adds support for the
X-Forwarded-Host
header in host matching. Should satisfy #3599.This only checks either the header or the request host with preference to former.
Should we check both?