Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

kennethklee
Copy link

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?

@CLAassistant
Copy link

CLAassistant commented Jul 28, 2020

CLA assistant check
All committers have signed the CLA.

@kennethklee kennethklee force-pushed the fwdhost branch 3 times, most recently from cdb23ac to 5d8cd0d Compare July 29, 2020 15:10
@francislavoie
Copy link
Member

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 X-Forwarded-Host header is correct.

Proxies should pass through the header with the actual Host header though, IMO it's strange if they only use X-Forwarded-Host, that's kinda non-standard.

@mholt
Copy link
Member

mholt commented Jul 31, 2020

Thanks for the PR!

But I'm not sure I understand... why can't you do this:

@fwdhost header X-Forwarded-For example.com

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?

@mholt mholt added the under review 🧐 Review is pending before merging label Aug 1, 2020
@kennethklee
Copy link
Author

kennethklee commented Aug 8, 2020

@francislavoie in terms of a security standpoint, the Host header will have the same implications. as such, if you're using business logic that trusts those headers you'll have a security bug. fortunately Caddy's address matchers impose a whitelist, in essence, to validate the input. as such, there's no security issue.

in my use case, caddy is behind a gateway. from the gateway, the Host header turns into the internal address of the proxied request i.e. app.local, whereas the original request host moves to the forwarded host header. both host and forwarded host headers exist.

@kennethklee
Copy link
Author

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.

@kennethklee
Copy link
Author

@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.

@mholt
Copy link
Member

mholt commented Aug 20, 2020

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).

@mholt mholt closed this Aug 20, 2020
@mholt mholt removed the under review 🧐 Review is pending before merging label Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants