Class: ActionDispatch::Session::EncryptedCookieStore

Inherits:
CookieStore
  • Object
show all
Defined in:
lib/encrypted_cookie_store.rb

Constant Summary collapse

SESSION_KEY =
if Rack.release >= '2'
  Rack::RACK_SESSION
else
  Rack::Session::Abstract::ENV_SESSION_KEY
end

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ EncryptedCookieStore

Returns a new instance of EncryptedCookieStore.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/encrypted_cookie_store.rb', line 22

def initialize(app, options = {})
  @logger = options.delete(:logger)
  @digest = options.delete(:digest) || 'SHA1'

  @compress = options[:compress]
  @compress = true if @compress.nil?

  @secret = options.delete(:secret)
  @secret = @secret.call if @secret.respond_to?(:call)
  @secret.freeze

  @data_cipher = OpenSSL::Cipher.new(EncryptedCookieStore.data_cipher_type)
  @encryption_key = unhex(@secret[0...(@data_cipher.key_len * 2)]).freeze
  ensure_encryption_key_secure
  options[:refresh_interval] ||= 5.minutes

  super(app, options)
end

Class Attribute Details

.data_cipher_typeObject

Returns the value of attribute data_cipher_type.



12
13
14
# File 'lib/encrypted_cookie_store.rb', line 12

def data_cipher_type
  @data_cipher_type
end

Instance Method Details

overrides method in ActionDispatch::Session::CookieStore



55
56
57
# File 'lib/encrypted_cookie_store.rb', line 55

def cookie_jar(request)
  request.cookie_jar
end

#fetch_header(env, key, &block) ⇒ Object



46
47
48
# File 'lib/encrypted_cookie_store.rb', line 46

def fetch_header(req, key, &block)
  req.fetch_header(key, &block)
end

#get_header(env, key) ⇒ Object



42
43
44
# File 'lib/encrypted_cookie_store.rb', line 42

def get_header(req, key)
  req.get_header(key)
end

#load_session(req) ⇒ Object

overrides method in Rack::Session::Cookie



83
84
85
86
87
88
# File 'lib/encrypted_cookie_store.rb', line 83

def load_session(req)
  if time = timestamp(req)
    fetch_header(req, 'encrypted_cookie_store.session_refreshed_at') { |k| set_header(req, k, Time.at(time).utc) }
  end
  super
end

#set_header(env, key, value) ⇒ Object



50
51
52
# File 'lib/encrypted_cookie_store.rb', line 50

def set_header(req, key, value)
  req.set_header(key, value)
end