Skip to content

Instantly share code, notes, and snippets.

@cmars
Created April 20, 2016 19:22
Show Gist options
  • Save cmars/0f2a5516ef8bdd71b62a64253b6d6cc2 to your computer and use it in GitHub Desktop.
Save cmars/0f2a5516ef8bdd71b62a64253b6d6cc2 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