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

handle multiple values in X-Forwarded-Proto #2162

Merged
merged 2 commits into from
Nov 16, 2017

Conversation

minrk
Copy link
Contributor

@minrk minrk commented Oct 13, 2017

use the first entry, which should be the outermost value

closes #2161

use the first entry, which should be the outermost value
@psyvision
Copy link

I've pulled @minrk commit and can confirm that when deployed into AWS it has resolved the issue with JupyterHub thinking the user requested via http instead of https.

@@ -287,6 +287,9 @@ def _apply_xheaders(self, headers):
proto_header = headers.get(
"X-Scheme", headers.get("X-Forwarded-Proto",
self.protocol))
if proto_header:
# use the outermost proto entry if there is more than one
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The outermost entry is the least reliable, so it's probably not what we want here. I think we either want the innermost, or we want to skip the same number of entries here that we did with trusted_downstream in the X-Forwarded-For list.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the use-case I'm interested in, the value required is the outermost as I don't want to set a cookie to be Secure if the original request wasn't https.

However, I could see a use-case where the end user was connecting with http but the proxy is connecting to the backend with https and that may have different meaning for the backend in that instance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to know whether the user's browser considers the request HTTPS, then even the outermost X-Forwarded-Proto isn't enough. Not all proxies set this header or support the multi-hop format here. I think if you want something that comes all the way from the user's browser you'll have to get it yourself with javascript.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matching the trusted_downstream behavior makes sense to me. I'll try to get that implemented soon.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...except, now that I think of it, it doesn't because it seems most proxies don't in practice append to x-forwarded-proto, so there isn't a reliable mapping of X-Forwarded-For and X-Forwarded-Proto entries.

That would suggest to me that it needs a dedicated trusted_proto_depth setting to set the index to lookup.

I'll set it to [-1] in this PR, and the setting for picking the outermost trusted value can be handled separately.

Copy link

@psyvision psyvision Nov 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minrk would that allow me to set additional configuration in JupyterHub to get the correct cookie setting set (as per the original issue)?

I don't really want to rely on injecting additional code in JupyterHub as @bdarnell suggested, whereas I might if it was a private project I had ownership of.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@psyvision in your specific case, I think you'll be okay because both hops happen to be https.

I'll follow @bdarnell's recommendation and investigate a more direct way for JupyterHub to identify whether the browser views the request as coming over https in the future, since what we really care about in that particular case is the Browser's opinion, not any of the proxy hops.

@minrk minrk force-pushed the forwarded-proto-list branch from e8f3b5e to 80959e4 Compare November 10, 2017 14:40
@bdarnell bdarnell merged commit 5fcfb42 into tornadoweb:master Nov 16, 2017
@minrk minrk deleted the forwarded-proto-list branch November 16, 2017 12:49
manics added a commit to manics/configurable-http-proxy that referenced this pull request Oct 15, 2020
manics added a commit to manics/configurable-http-proxy that referenced this pull request Oct 15, 2020
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.

X-Forwarded-Proto Multiple Values
3 participants