Skip to content

Instantly share code, notes, and snippets.

@clod81
Last active April 10, 2023 04:30
Show Gist options
  • Save clod81/6771028c5107368392d3f5a2ecd4ca32 to your computer and use it in GitHub Desktop.
Save clod81/6771028c5107368392d3f5a2ecd4ca32 to your computer and use it in GitHub Desktop.
Parse a json of cookies and returns the document.cookie directives to be run in dev console in browser in the target domain
import json
cookies = '[{"name":"cookiename","value":"cookievalue","domain":"domain.com","path":"/","expires":1710446521.314705,"size":8,"httpOnly":false,"secure":true,"session":false,"priority":"Medium","sameParty":false,"sourceScheme":"Secure","sourcePort":443}]'
parsed = json.loads(cookies)
# print("")
# print("Set-Cookie: ******************************")
# print("")
# for c in parsed:
# print("Set-Cookie: " + c['name'] + "=" + c['value'])
print("")
print("document.cookie ******************************")
print("")
for c in parsed:
name = c['name'].replace('"', '\\"')
value = c['value'].replace('"', '\\"')
domain = c['domain']
if domain.startswith("."):
domain = domain.replace(".", "", 1)
print('document.cookie = "' + name + '=' + value + '; Secure; path=' + c['path'] + '; domain=' + domain + '"')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment