Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use alternative serializer #6

Open
namelessjon opened this issue Nov 30, 2013 · 3 comments
Open

Use alternative serializer #6

namelessjon opened this issue Nov 30, 2013 · 3 comments

Comments

@namelessjon
Copy link
Collaborator

a la https://gist.github.com/mattetti/7624413

tl;dr: encrypted_cookie currently serializes via marshall. This means that anyone who discovers the session secret probably has remote code execution on the application. Which is pretty bad, obviously.

@mkristian
Copy link
Contributor

personally I store a Hash with primitive in my session. so a json or (safe_)yaml would just do fine. via some config/options or so !!

@namelessjon
Copy link
Collaborator Author

*several months elapse*

One snag in implementing this easily is the expiry time which was added. With e.g. JSON.dump, this is serialised to something like "2014-08-15 14:46:26 UTC" and then on JSON.load it is returned as a string, which can't be compared with the Time.

Options

  1. Add a check in the expiry code to Time.parse if given a string.
  2. Write some new JSON and/or YAML based serialiser which converts everything to primitives.
  3. Something else?

@tonytonyjan
Copy link

tonytonyjan commented Dec 5, 2016

Since the project seems no longer under maintained, I built another one:
https://github.com/tonytonyjan/rack_encrypted_cookie

It's built on top of Rack::Session::Cookie, so you can customize the :coder as well, for example:

use Rack::Session::EncryptedCookie, secret: 'tonytonyjan', coder: Rack::Session::Cookie::Base64::JSON.new

There are 3 built -in serializers (coders) so far:

puts Rack::Session::Cookie::Base64.constants
# => [:Marshal, :JSON, :ZipJSON]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants