New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

encrypted_cookie

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

encrypted_cookie

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Encrypted session cookies for Rack (and therefore Sinatra)

Ruby

The encrypted_cookie gem provides 256-bit-AES-encrypted, tamper-proof cookies for Rack through the class Rack::Session::EncryptedCookie.

$ gem install encrypted_cookie

Sinatra example:

require 'sinatra'
require 'encrypted_cookie'

use Rack::Session::EncryptedCookie,
  :secret => TYPE_YOUR_LONG_RANDOM_STRING_HERE*

get '/' do
  session[:foo] = 'bar'
  "session: " + session.inspect
end

* Your :secret must be at least 32 bytes long and should be really random. Don't use a password or passphrase, generate something random (see below).

Encryption and integrity protection

The cookie is encrypted with 256-bit AES in CBC mode (with random IV). The encrypted cookie is then signed with a HMAC, to prevent tampering and chosen ciphertext attacks. Any attempt at tampering with the cookie will reset the user to {} (empty hash).

Generating a good secret

Run this in a terminal and paste the output into your script:

$ ruby -rsecurerandom -e "puts SecureRandom.hex(32)"

Developing

To get the specs running:

$ cd path-to-clone
$ gem install bundler # if not already installed
$ bundle install
$ bundle exec rspec

Thanks

  • @namelessjon - Jon - For the massive crypto improvements!
  • @mkristian - Christian Meier
  • @danp - Dan Peterson
  • @stmllr - Steffen Müller
  • @andrhamm - Andrew Hammond

FAQs

Package last updated on 17 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc