Skip to content

Instantly share code, notes, and snippets.

@eik3
Created August 19, 2010 15:50
Show Gist options
  • Save eik3/538210 to your computer and use it in GitHub Desktop.
Save eik3/538210 to your computer and use it in GitHub Desktop.
A script to decode the Rails _session cookie
#!/usr/bin/env ruby
# This interactive script decodes the _session cookie contents of the Rails
# Session Store. It can be useful when debugging session-related problems.
# Be aware that Firefox doesn't update the cookie contents on every request when
# you keep the according dialog open. If you have to debug HTTP regularly, I can
# recommend the Charles Web Debugging Proxy (http://www.charlesproxy.com/)
puts("Loading...")
Signal.trap("INT") { puts "\n" ; exit }
require File.join(File.dirname(__FILE__), "..", "config", "environment")
# alternatively, require cgi and base64
require "pp"
puts "Ready. Paste _session cookie contents to decode, press enter for new line, CTRL-C to exit."
session_cookie=gets
while true do
unless session_cookie=="\n"
puts "-" * 80
begin
pp Marshal.load(Base64.decode64(CGI.unescape(session_cookie).split('--').first))
rescue ArgumentError,TypeError
puts "ERROR: could not decode that."
end
puts "_" * 80
end
session_cookie=gets
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment