-
Notifications
You must be signed in to change notification settings - Fork 14
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
allow secure session cookies through proxy or to localhost #41
allow secure session cookies through proxy or to localhost #41
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking like a step in the right direction, but we should also add tests.
I would need some guidance on how to write tests. |
@jrmcgarvey review the existing test suite for examples. I'd recommend a test for the default option, as well as the request.host == 'localhost'. You only need to unit test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine once a test is added.
Something like "I trust my proxy [not to... do a bad thing?]" is not the same as "I trust my proxy to recognise and apply |
Ok, tests added. |
I chose "trust_proxy" because that is what is used in Express for the same purpose. Perhaps it should be "always_write_cookie", as that is what is used in Rails for non-session cookies, although this is not documented. |
What about |
We need to reflect on what is implemented today. I took a look at the logic in https://github.com/rack/rack/blob/main/lib/rack/request.rb . It seems like one could spoof things just by setting X-Forwarded-Proto to HTTPS, or some other equivalent header. I haven't seen any best practices on how proxies are to be configured for this. If there are intermediate proxies between the one that terminates the HTTPS connection and the actual server, should X-Forwarded-Proto be passed on through to the server? Having several hops might defeat the purpose of SSL in protecting data in transit. And, of course, not all proxies are even configured to set such headers. The 'trust proxy' setting in Express provides various ways to configure things, viz: proxies, for which Rails has no equivalent. I don't know how this configuration affects things other than secure cookies. force_secure sounds like one is forcing the cookie to be secure. Maybe trust_proxy_with_cookie? |
I see - so what's happening here is, we have
I understand now what @matthewd was saying. What we are really doing here is saying "We assume downstream that the connection is SSL/secure, e.g. Additionally, I'm not sure that I'd like you to feel the full weight of the security implications here. If we are wrong about this, it could be a major security issue. Therefore, might I suggest the following:
We can definitely merge the former, but the latter has a higher bar IMHO. Is this a reasonable course of action? |
Ok, I will take out the localhost part, and change to assume_ssl. One could set that value for development, and not set it, if it is inappropriate, in production. It would be nice if other Rails cookies were handled with the same flag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
One idea I had, is we could allow
(separate PR after this one). |
It should be possible to make session cookies secure but also to send them when not running SSL, in two cases:
For the latter case, an options flag is added, trust_proxy, and the secure cookie is sent if that is true.
The direction of browser vendors is not to allow credentials to be included on fetch requests unless the cookies are secure and sameSite=None. This change allows Rails to return the session cookie as a credential for subsequent fetch requests. Also, it is useful to be able to make the session cookie secure in typical cloud deployments, when the Rails server is behind a proxy.
resolves issue #40