123456789_123456789_123456789_123456789_123456789_

Class: ActionDispatch::Cookies::SignedKeyRotatingCookieJar

Do not use. This class is for internal use only.
Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: ActionDispatch::Cookies::AbstractCookieJar
Defined in: actionpack/lib/action_dispatch/middleware/cookies.rb

Constant Summary

SerializedCookieJars - Included

SERIALIZER

Class Method Summary

Instance Attribute Summary

Instance Method Summary

SerializedCookieJars - Included

AbstractCookieJar - Inherited

ChainedCookieJars - Included

#encrypted

Returns a jar that’ll automatically encrypt cookie values before sending them to the client and will decrypt them for read.

#permanent

Returns a jar that’ll automatically set the assigned cookies to have an expiration date 20 years from now.

#signed

Returns a jar that’ll automatically generate a signed representation of cookie value and verify it when reading from the cookie again.

#signed_or_encrypted

Returns the signed or encrypted jar, preferring encrypted if secret_key_base is set.

#encrypted_cookie_cipher, #signed_cookie_digest

Constructor Details

.new(parent_jar) ⇒ SignedKeyRotatingCookieJar

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/cookies.rb', line 622

def initialize(parent_jar)
  super

  secret = request.key_generator.generate_key(request.signed_cookie_salt)
  @verifier = ActiveSupport::MessageVerifier.new(secret, digest: signed_cookie_digest, serializer: SERIALIZER)

  request.cookies_rotations.signed.each do |(*secrets)|
    options = secrets.extract_options!
    @verifier.rotate(*secrets, serializer: SERIALIZER, **options)
  end
end

Instance Method Details

#commit(name, options) (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/cookies.rb', line 641

def commit(name, options)
  super
  options[:value] = @verifier.generate(options[:value], **(name, options))
  check_for_overflow!(name, options)
end

#parse(name, signed_message, purpose: nil) (private)

[ GitHub ]

  
# File 'actionpack/lib/action_dispatch/middleware/cookies.rb', line 635

def parse(name, signed_message, purpose: nil)
  rotated = false
  data = @verifier.verified(signed_message, purpose: purpose, on_rotation: -> { rotated = true })
  super(name, data, force_reserialize: rotated)
end