G
YouTube TikTok Games
Skip to content

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

Open

Description

@jrmcgarvey

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

Activity

  1. ioquatix commented on Feb 29, 2024

    @ioquatix
    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.

  2. jrmcgarvey commented on Feb 29, 2024

    @jrmcgarvey
    ContributorAuthor

    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.

  3. ioquatix commented on Mar 3, 2024

    @ioquatix
    Member

    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.

  4. jrmcgarvey commented on Mar 4, 2024

    @jrmcgarvey
    ContributorAuthor

    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.

  5. ioquatix commented on Mar 4, 2024

    @ioquatix
    Member

    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.

  6. jrmcgarvey commented on Mar 4, 2024

    @jrmcgarvey
    ContributorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions