Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Can't get valid session key via request.session_options[:key] when using CookieStore

#4742

Hi!
When I try to get session key via request.session_options[:key], I always get '_session_id' even though I changed it in session_store.rb (or production.rb)

I found the source code in cookie_store.rb like this

      def initialize(app, options = {})

    # Process legacy CGI options
    options = options.symbolize_keys
    if options.has_key?(:session_path)
      options[:path] = options.delete(:session_path)
    end
    if options.has_key?(:session_key)
      options[:key] = options.delete(:session_key)
    end
    if options.has_key?(:session_http_only)
      options[:httponly] = options.delete(:session_http_only)
    end

    @app = app

    # The session_key option is required.
    ensure_session_key(options[:key])
    @key = options.delete(:key).freeze

    # The secret option is required.
    ensure_secret_secure(options[:secret])
    @secret = options.delete(:secret).freeze

    @digest = options.delete(:digest) || 'SHA1'
    @verifier = verifier_for(@secret, @digest)

    @default_options = DEFAULT_OPTIONS.merge(options).freeze

    freeze
  end</code>



I think because @default_options[:key] was not changed due to @key = options.delete(:key).freeze

It doesn't occur when I use memcache as session store, so I tried to figure it why.
And I found initialize method in abstract_store.rb and also found that the method does not delete :key from options.

How can I get valid session key if this is not a bug?

Reported by brian · June 1st, 2010 @ 04:49 AM

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Neeraj Singh
    Neeraj Singh

    @Brian: Can you show the code that you put in session_store.rb to get full picture?

    June 1st, 2010 @ 10:03 AM

  2. brian
    brian

    my session_store.rb is like this

    ActionController::Base.session = {
      :key         => '_waffle_session',
      :secret      => 'xxxxxxxx',
    }
    

    and my production.rb is like this

    #config.action_controller.session_store = :mem_cache_store
    config.action_controller.session = {
      :key         => "_waffle_session",
      :secret      => 'xxxxxxxx(same with secret in session_store.rb)',
    #  :expires     => 3600,
      :cookie_only => false,
    #  :cache       => CACHE,
    }
    

    thank you

    June 1st, 2010 @ 10:46 AM

  3. dr
    dr

    I'm having a similar issue. That is, you don't seem to be able to set the session options because session_options isn't being passed down to AbstractStore.

    Setting

    Rails.application.config.session_options[:key] = 'something_other_than_session_id'

    doesn't change the cookie name

    July 14th, 2010 @ 12:29 AM

  4. dr
    dr

    Okay, I dug a little deeper and see in Rails 3 that should be:

    Rails.application.config.session_store :active_record_store, { :key => 'something_other_than_session_id' }
    

    Which works for :cookie_store, but not for :active_record_store.

    Adding:

    
    def initialize(app, options = {})
      super
    end
    

    to ActiveRecord::SessionStore fixes the problem. Although I don't see why it's necessary.

    July 14th, 2010 @ 03:02 AM

  5. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:36 PM

  6. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:36 PM

  7. bingbing
  8. ssupreme11
    ssupreme11

    Its my first time to visit this site and as I was exploring I cant believe that this site was made up of a very informative articles that you should try to have compliment with so as what I am doing now I really love to look forward with more interesting information on this site.. Buy Dissertation

    May 10th, 2011 @ 10:25 PM