Skip to content

Instantly share code, notes, and snippets.

@nickhs
Created April 16, 2013 01:24
Show Gist options
  • Save nickhs/5392647 to your computer and use it in GitHub Desktop.
Save nickhs/5392647 to your computer and use it in GitHub Desktop.
Decrypt cookie
# Cookie is named session in the client browser, is set to persist across subdomains (so foobar.com and app.foobar.com will
# still be valid).
#!/usr/bin/env python
import base64
cookie = 'eyJjb21wYW55IjoiZm9vYmFyIiwidXNlcl9pZCI6NSwiZW1haWwiOiJuaWNrQG5pY2tocy5jb20ifQ.BE43Cw.7CUdWGN2mjcKsRdOOtrIamCv09s'
info, timestamp, signature = cookie.split('.')
padding = -len(info) % 4 * '='
info = info + padding
print base64.urlsafe_b64decode(info)
# result: '{"company":"foobar","user_id":5,"email":"nick@nickhs.com"}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment