Skip to content

Instantly share code, notes, and snippets.

@mattyw
Forked from cmars/show_cookies.py
Created May 17, 2016 09:46
Show Gist options
  • Save mattyw/4b96555465ca83c905cee6a603b50cb7 to your computer and use it in GitHub Desktop.
Save mattyw/4b96555465ca83c905cee6a603b50cb7 to your computer and use it in GitHub Desktop.
Show ~/.go-cookies content without compromising authorization tokens
#!/usr/bin/env python3
import base64
import json
import os
import sys
if __name__ == '__main__':
if sys.argv[1:]:
filename = sys.argv[1]
else:
filename = "%s/.go-cookies" % (os.environ["HOME"])
with open(filename, "r", encoding='utf8') as f:
cookies = json.load(f)
for cookie in cookies:
value_enc = cookie.get('Value')
if not value_enc:
continue
value = base64.b64decode(value_enc)
macaroons = json.loads(value.decode('utf8'))
for macaroon in macaroons:
if macaroon.get('signature'):
macaroon['signature'] = 'scrubbed'
if macaroon.get('identifier'):
macaroon['identifier'] = 'scrubbed'
for caveat in macaroon.get('caveats', []):
if caveat.get('vid'):
caveat['vid'] = 'scrubbed'
if caveat.get('cid'):
caveat['cid'] = 'scrubbed'
cookie['Value'] = macaroons
json.dump(cookies, sys.stdout, indent=4, sort_keys=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment