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.

Inconsistent session cookie value from marshalled hash

#2623

When using CookieStore there can be cases where the session cookie is inconsistent between requests. This is caused by marshalling an unmarshalling of a Hash of which the ordering is not guaranteed (nor consistent). The resulting marshalled value will be different causing a different value for the session cookie. However when unmarshalled it will still be the same hash so it does not effect the way the session is persistent unless you were relying on the session cookie to be persistent between requests (i.e. for a flash uploader).

i.e.

session[:foo] = 'bar'
session[:biz] = 'bam'

may unpredictably result in this:

>> Marshal.dump(:foo => 'bar', :biz => 'bam')
=> "\004\b{\a:\bbiz\"\bbam:\bfoo\"\bbar"

or this:

>> Marshal.dump(:biz => 'bam', :foo => 'bar')
=> "\004\b{\a:\bfoo\"\bbar:\bbiz\"\bbam"

The attached patch changes CookieStore to sort the hash into an array before marshalling, and to rebuild a hash from the sorted array on unmarshalling to avoid the inconsistent nature of a hash.

I could not find a way to duplicate the failing case in a test because it relies on how the hash ends up being marshalled, which is inconsistent, which is the whole problem in the first place.

Reported by Ben Alavi · May 8th, 2009 @ 04:11 AM

State: invalid
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. Ben Alavi
    Ben Alavi

    After digging into this a lot more I can't find a reason why this should matter.

    I'm pretty sure this is invalid.

    May 8th, 2009 @ 05:10 AM

  2. Ben Alavi
    Ben Alavi
    • Tag changed from action_pack, cookie_store, patch to action_pack, cookie_store, invalid, patch

    May 8th, 2009 @ 05:12 AM

  3. Ben Alavi
    Ben Alavi

    After playing with MessageVerifier more this is definitely invalid.

    May 8th, 2009 @ 05:46 AM

  4. Frederick Cheung
    Frederick Cheung
    • State changed from new to invalid

    May 10th, 2009 @ 04:19 PM