-
Notifications
You must be signed in to change notification settings - Fork 89
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
Host port should default to 80 if the Host header has been set #106
Comments
Bandit explicitly falls back to the port of the underlying transport if not set in the References:
Do you have details on the ueberauth issue so we can see if it can be fixed there? |
@mtrudel I glanced over the referenced RFC7540§8.1.2.3 section and don't see anything clearly stating the above ( i might have missed something). I do see the default port for scheme http is 80 and https is 443, but this does not seem to be respected by cowboy as it just defaults to 80, even if the x-forwarded-proto is set to https. My concern was more around packages with the plug dependency potentially relying on this "issue". I will submit a patch for ueberauth and link this issue, as ueberauth blindly assumes https with port 80 should normalise to port 443. |
To my (at least somewhat learned) understanding, there isn't really an explicitly correct answer to this in the specs. I think the closest thing you're going to find to a normative answer is RFC9110§7.2. A couple of other places weigh in:
So I don't think that the specs have a specific answer here. The more I think about this though, the less I think that this is really super important when it all comes down to it. Ultimately, this comes down to what we want If it's what the user thinks they're connecting to, then Cowboy defaulting to port 80 is probably the right thing (setting aside that this makes some assumptions about the client's intent that, as above, seem to be undefined). If it's what the user is actually connected to, then we do the right thing today. I believe the second of these options to be the more correct one. One of Bandit's fundamental goals is to codify a minimum of policy, and I see option 2 as furthering this goal more effectively. There is no way to not editorialize, at least somewhat, an answer to the first question, whereas there is a clear & objectively correct answer to the second. I'll take that option every time. If the user wants to figure out an answer to the first question, they can do so with full view of the inherent editorializing that goes into answering it. I don't think that's Bandit's job here. Of course, all of the above is premised on the RFCs not being specifically normative on this point. If there's a clause somewhere that spells this behaviour out, I will happily tack that way (as I've said before, being correct is Bandit's literal prime directive). |
I just want to use bandit and ueberauth 😆 and do see why defaulting to 80 can be seen as a hack. Here is a draft PR for ueberauth which solves the issue: ueberauth/ueberauth#181. Thanks for the detailed response and a great library. |
As @wkirschbaum thoughtfully lays out the sketch for here, I think the specs actually are normative on this:
All of which is to say that I'm now convinced that the RFCs have a normative stance on this, and we should change to accommodate this. Note that this means that Bandit will now have to adopt the notion that ' I'll cut a Bandit PR in the next couple of days to adopt this behaviour. Specifically, the change will be to no longer consult the underlying transport when ports are not explicitly provided in the request URI or host headers, but rather to use the scheme's default. No other behaviour in terms of absolute URI vs host header precedence will change. I think this will resolve the issue in ueberauth/ueberauth#187. |
Assuming we want to keep compatibility with cowboy:
When the host header is set with cowboy without an explicit port, cowboy will default to port 80.
To reproduce:
curl -H "Host: foo.co.za" http://localhost:4000
Should set conn.port to 80
Should set conn.port to 4000
and
curl -H "Host: foo.co.za:9999" http://localhost:4000
Should set conn.port to 9999
This is currently a issue with ueberauth when generating the callback_url.
The text was updated successfully, but these errors were encountered: