5

One example of a Rails 2.3.8 session cookie is

BAh7BzoLZm9vYmFyaQc6D3Nlc3Npb25faWQiJWIzOTRhNGFkNDg1Mjk2NGM2NDU1Mzc4ZTM0YjkzZjE2--67046ba78aa6d656ec7c64e73aac156f5e503627

so I assume the second part (after the --)is a checksum, and if a Base64 decode is done:

$ script/console
Loading development environment (Rails 2.3.8)

 > Base64.decode64("BAh7BzoLZm9vYmFyaQc6D3Nlc3Npb25faWQiJWIzOTRhNGFkNDg1Mjk2NGM2NDU1Mzc4ZTM0YjkzZjE2")
 => "\004\b{\a:\vfoobari\a:\017session_id\"%b394a4ad4852964c6455378e34b93f16" 

 > puts Base64.decode64("BAh7BzoLZm9vYmFyaQc6D3Nlc3Npb25faWQiJWIzOTRhNGFkNDg1Mjk2NGM2NDU1Mzc4ZTM0YjkzZjE2")
{:
  foobari:session_id"%b394a4ad4852964c6455378e34b93f16

supposedly foobar should have a value of 2 and it won't show... and what is the session_id for if it is based on a cookie -- why does it need an id?

1 Answer 1

8

The code after the -- is a SHA, hashed with the session secrect defined in the application.

And here about the ID.

Edit:

Marshal.load(Base64.decode64("BAh7BzoLZm9vYmFyaQc6D3Nlc3Npb25faWQiJWIzOTRhNGFkNDg1Mjk2NGM2NDU1Mzc4ZTM0YjkzZjE2--67046ba78aa6d656ec7c64e73aac156f5e503627".split('--').first))

=> {:foobar=>2, :session_id=>"b394a4ad4852964c6455378e34b93f16"}
2
  • so when decoding, the remove the -- and the hex string after it. so it should come out fine, shouldn't it? Mar 3, 2011 at 2:53
  • @動靜能量 Yes and then you have to deserialize it with Marshal. I have edited my answer.
    – pseidemann
    Mar 17, 2011 at 7:35

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.