I am studying the structure of Sinatra and developing a login system. I came across two ways to use cookies.
Simple built-in Sinatra method:
enable :sessions set :session_secret, 'random-key'
This approach creates the following cookie at login time (using session.inspect to get the result):
{"session_id"=>"6be0b9a31831604ba51114d265ba952482e0b2da6ced6c54e15ebe7f212858ca", "tracking"=>{"HTTP_USER_AGENT"=>"b8c1e8f89eeaea0b825bed0d811f0c7678e98c74", "HTTP_ACCEPT_ENCODING"=>"a0bfc876d68fe7aea700da5ea8925abac6f2f794", "HTTP_ACCEPT_LANGUAGE"=>"dd065ed263c67d799f943ab6c39b55c5e008cbb5"}, "csrf"=>"b480324f510e4f391d15cee8236a8fb74a5aaa5ce2f9ad38e4dbb025a823b16e", "name"=>"john"}
Another approach is to use an encrypted cookie:
require 'sinatra' require 'encrypted_cookie' use Rack::Session::EncryptedCookie, :secret => "random-key"
But this approach leads to the following cookie contents on login ( session.inspect used here):
{:name=>"john"}
Why enable :sessions creates such a large cookie with all this information and why it is needed (especially those parts of HTTP _...?) Since Rack::Session::EncryptedCookie does not generate any of them.
Do you think using enable :sessions should be preferred since it has a csrf token and session id? Or do you think that Rack::Session::EncryptedCookie enough because it is encrypted?
I have the following versions of installed stones:
encrypted_cookie (0.0.4) rack (1.5.2) rack_csrf (2.4.0) sinatra (1.4.3) thin (1.5.1)
Please tell me if you need more information ...