diff options
author | Rich Cavanaugh <cavanaugh@fatjam.com> | 2008-05-12 15:25:56 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-05-12 15:26:19 -0700 |
commit | a425cd147363a0e8d7e17177ef252dd760197f15 (patch) | |
tree | d992a97129c45fe67028e8ba372164cd4ca03568 /actionpack/lib | |
parent | cde6a259bf46cdaf1f2fe5fdeb84478ca8fc3046 (diff) | |
download | rails-a425cd147363a0e8d7e17177ef252dd760197f15.tar.gz rails-a425cd147363a0e8d7e17177ef252dd760197f15.tar.bz2 rails-a425cd147363a0e8d7e17177ef252dd760197f15.zip |
Don't double-escape cookie store data. Don't split cookie values with newlines into an array. [#130 state:resolved]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/cgi_ext/cookie.rb | 2 | ||||
-rw-r--r-- | actionpack/lib/action_controller/session/cookie_store.rb | 9 |
2 files changed, 7 insertions, 4 deletions
diff --git a/actionpack/lib/action_controller/cgi_ext/cookie.rb b/actionpack/lib/action_controller/cgi_ext/cookie.rb index 3dd374f126..e35bab5f5a 100644 --- a/actionpack/lib/action_controller/cgi_ext/cookie.rb +++ b/actionpack/lib/action_controller/cgi_ext/cookie.rb @@ -37,7 +37,7 @@ class CGI #:nodoc: @path = nil else @name = name['name'] - @value = Array(name['value']) + @value = name['value'].kind_of?(String) ? [name['value']] : Array(name['value']) @domain = name['domain'] @expires = name['expires'] @secure = name['secure'] || false diff --git a/actionpack/lib/action_controller/session/cookie_store.rb b/actionpack/lib/action_controller/session/cookie_store.rb index 560491f996..ada1862c3e 100644 --- a/actionpack/lib/action_controller/session/cookie_store.rb +++ b/actionpack/lib/action_controller/session/cookie_store.rb @@ -130,17 +130,20 @@ class CGI::Session::CookieStore # Marshal a session hash into safe cookie data. Include an integrity hash. def marshal(session) data = ActiveSupport::Base64.encode64(Marshal.dump(session)).chop - CGI.escape "#{data}--#{generate_digest(data)}" + "#{data}--#{generate_digest(data)}" end # Unmarshal cookie data to a hash and verify its integrity. def unmarshal(cookie) if cookie - data, digest = CGI.unescape(cookie).split('--') - unless digest == generate_digest(data) + data, digest = cookie.split('--') + + # Do two checks to transparently support old double-escaped data. + unless digest == generate_digest(data) || digest == generate_digest(data = CGI.unescape(data)) delete raise TamperedWithCookie end + Marshal.load(ActiveSupport::Base64.decode64(data)) end end |