Skip to content

Instantly share code, notes, and snippets.

@bruz
Created April 20, 2017 20:39
Show Gist options
  • Save bruz/fab4cae0275a756b7e88245fc761c434 to your computer and use it in GitHub Desktop.
Save bruz/fab4cae0275a756b7e88245fc761c434 to your computer and use it in GitHub Desktop.
Decrypt Rails 4 session cookie
# `cookie` is the session cookie string
message = URI.unescape cookie
config = Rails.application.config
key_generator = ActiveSupport::KeyGenerator.new(
Rails.application.secrets.secret_key_base, iterations: 1000
)
secret = key_generator.generate_key(
config.action_dispatch.encrypted_cookie_salt
)
sign_secret = key_generator.generate_key(
config.action_dispatch.encrypted_signed_cookie_salt
)
encryptor = ActiveSupport::MessageEncryptor.new(secret, sign_secret, serializer: JSON)
encryptor.decrypt_and_verify message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment