-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
get_host will use X-Forwarded-Host by default #609
Comments
Yeah that's actually pretty terrible. |
It actually turns out this isn't a security issue.
|
I disagree: while the user can specify arbitrary
This documentation is at odds with the behaviour of the
There are cases when you need to be able to trust the
Therefore, I personally believe that it should not trust |
Can't argue with that. |
I'm a bit confused about the exact issue here but I'm not opposed to changing it. In any case the documentation should clearly mention this behavior. The way the system works is this: the server has two sources for where the host can come from: the
You cannot trust the host parameter. That's entirely impossible because nothing stops a client from forging the request. What you can do however is to make sure you only allow a single host value (by setting the trusted hosts to a list of that one host that is valid). I'm not ruling out I'm wrong on this but I would love to hear where the mistake in thinking is. |
So the 'mistake' is the documentation; AFAICT nothing mentions this behaviour, and documentation for other things ( However, this 'mistake' would also be fixed by changing the behaviour of I guess I've been simultaneously arguing both points in the same issue.
I think that ultimately what I'm saying is that while people are likely to sanitise the I believe that it's quite likely that this could catch someone out, if they don't happen to read that section of the docs. Having to explicitly enable support for |
AFAICT Werkzeug's default behavior seems to be problematic if no proxy is used, but the hostname is still used for delegating the requests to the correct application (i think that's the case when using Apache vhosts and mod_wsgi, though i never used such a setup). In that case the user could send a |
The problem with that is that you break all the things that currently rely on this behavior which I assume are many. I know that I generally do not use a middleware to fix it up. It also has been behavior for many years and is documented on the
Out of curiosity: how do you sanitize the host header? |
My Host header is sanitised as a side-effect of nginx's virtual hosting. The whitelist is in I believe this has been discussed before: I'm curious as to the situations in which |
Removing blocker label because the fix is breaking backwards-compat. |
Could you at least fix the documentation here https://github.com/mitsuhiko/werkzeug/blob/master/werkzeug/wrappers.py#L191 to mention that both
...and we can discuss whether or not this is a sane default behaviour or not later? |
I think we should document this in the docstring of get_host and refer to it in this param's docstring. What do you think? Also, if you have concrete ideas about the wording, patches welcome! :) |
Do you think that the documentation for the |
I have no opinion or idea about this at all... I find it hard to predict how users will read your documentation. |
Yeah looks great! I merged your changes for now, and hopefully we'll be able to figure out something better for 1.0. Thanks, not only for the patch, but for bringing this issue up @danielrichman! |
Okay, so: the current documentation correctly describes the current behaviour, however, I believe this issue should stay open since I do not think that using X-Forwarded-Host is a sensible default. To summarise arguments so far: @mitsuhiko (correctly) says
I argue that this violates the principle of least surprise.
Miscellaneous
|
I did not close it! I just postponed it to version
I can imagine that developers don't do anything if the current behavior seems to "work". Thanks for the summary. |
@untitaker I have marked this as a blocker. We should fix this in the next feature release. Waiting for 1.0 is too long. People should be using |
👍 for not doing any implicit HTTP_X_FORWARDED overrides and having people use ProxyFix for it |
Yep, we've just been surprised to find this is the case. |
Here: https://github.com/mitsuhiko/werkzeug/blob/cbd049d88727936173386d2e80bb5ffa51fedd6e/werkzeug/wsgi.py#L141
I don't think that this is a safe default.
When using flask it gives any client the ability to set an arbitrary hostname in
request.url
.This surprised me, since http://werkzeug.pocoo.org/docs/0.9/contrib/fixers/#werkzeug.contrib.fixers.ProxyFix exists to explicitly enable support for these headers (
X-Forwarded-For
,X-Forwarded-Host
, ...).And I think that this is misleading: http://werkzeug.pocoo.org/docs/0.9/wrappers/#werkzeug.wrappers.BaseRequest.trusted_hosts since a web server must not only “not route invalid hosts to the application”, but it must also delete any foreign
X-Forwarded-Host
headers.The text was updated successfully, but these errors were encountered: