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

Need to be able to send secure session cookie for localhost #40

Open
jrmcgarvey opened this issue Feb 29, 2024 · 6 comments
Open

Need to be able to send secure session cookie for localhost #40

jrmcgarvey opened this issue Feb 29, 2024 · 6 comments

Comments

@jrmcgarvey
Copy link
Contributor

Right now, unless it is ssl, you can't send a secure session cookie. It is perfectly valid to do this for localhost, and very desirable for development.

In lib/rack/session/abstract/id.rb, I think it should say something like:

def security_matches?(request,options)
return true unless options[:secure]
request.ssl? || request.host == "localhost"
end

@ioquatix
Copy link
Member

That seems reasonable to me, but I don't fully grok the implications. Do you mind submitting a PR? Then we can discuss the specifics.

@jrmcgarvey
Copy link
Contributor Author

I can. It's a little confusing, because Rails sets cookies two ways, one for sessions, one for all other cookies. For other cookies, Rails does not document how to send secure cookies when the app is in production behind a proxy, so that requests are not coming over ssl. But I'll submit a PR.

One background issue is that when Rails is used as a back end, it would be nice to use the httpOnly session cookie, so that one doesn't have to adopt the risky strategy of storing auth tokens in local storage -- but the browser vendors are on a path to eliminate third party cookies.

@ioquatix
Copy link
Member

ioquatix commented Mar 3, 2024

It is perfectly valid to do this for localhost

Is there any other evidence (library implementation, framework, documentation) to support this assertion? It would be extremely helpful to understand the broader context.

@jrmcgarvey
Copy link
Contributor Author

Yes, this is documented here. RFC 6265 punts to the browser implementation on the question of what constitutes a secure connection. See my response on the PR.

@ioquatix
Copy link
Member

ioquatix commented Mar 4, 2024

Just for reference, I assume we are talking about:

A cookie with the Secure attribute is only sent to the server with an encrypted request over the HTTPS protocol. It's never sent with unsecured HTTP (except on localhost), which means man-in-the-middle attackers can't access it easily. Insecure sites (with http: in the URL) can't set cookies with the Secure attribute. However, don't assume that Secure prevents all access to sensitive information in cookies. For example, someone with access to the client's hard disk (or JavaScript if the HttpOnly attribute isn't set) can read and modify the information.

@jrmcgarvey
Copy link
Contributor Author

Yes, that's the only reference I can find on the issue, other than the RFC.

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

No branches or pull requests

2 participants