checkcookies.py
What is actually in the browser's cookie store
68 lines. This is the file the build actually runs, copied verbatim at build time.
- 1
"""Any cookie set while loading the site, read from Chrome's own cookie store. - 2
- 3
Every page footer says "no cookies". checklive.py only ever checked for a - 4
Set-Cookie *header* — but a script can set one with document.cookie, and - 5
Cloudflare runs a fingerprinting script on every page here. So the claim was - 6
verified in the one place it was least likely to fail. - 7
- 8
Run shot.sh against a page first (ideally after deleting the profile, so the - 9
store starts empty), then: - 10
- 11
python3 checkcookies.py - 12
""" - 13
- 14
import os - 15
import sqlite3 - 16
import sys - 17
- 18
PROFILE = "/var/www/sweedworks/.chrome-home" - 19
STORE = os.path.join(PROFILE, "Default", "Cookies") - 20
- 21
- 22
def main(): - 23
if not os.path.exists(STORE): - 24
print(f"no cookie store at {STORE}") - 25
print("Chrome did not create one, which means nothing tried to set a " - 26
"cookie.") - 27
return 0 - 28
- 29
# Copy first: the store may be locked, and we must not modify it. - 30
tmp = "/tmp/claude-996/cookies-copy.sqlite" - 31
with open(STORE, "rb") as src, open(tmp, "wb") as dst: - 32
dst.write(src.read()) - 33
- 34
con = sqlite3.connect(tmp) - 35
try: - 36
rows = con.execute( - 37
"SELECT host_key, name, path, is_secure, is_httponly, " - 38
"has_expires, is_persistent FROM cookies").fetchall() - 39
except sqlite3.DatabaseError as e: - 40
print(f"could not read cookie store: {e}") - 41
return 1 - 42
finally: - 43
con.close() - 44
- 45
if not rows: - 46
print(f"cookie store exists ({os.path.getsize(STORE)} bytes) but holds " - 47
f"no cookies.") - 48
print("Nothing set a cookie while loading the site.") - 49
return 0 - 50
- 51
print(f"{len(rows)} cookie(s) present:") - 52
for host, name, path, secure, httponly, has_exp, persistent in rows: - 53
flags = [] - 54
if secure: - 55
flags.append("secure") - 56
if httponly: - 57
flags.append("httpOnly") - 58
flags.append("persistent" if persistent else "session") - 59
print(f" {host:<24} {name:<24} {path:<10} {', '.join(flags)}") - 60
- 61
print() - 62
print("The footer says 'no cookies'. That is now false, or needs qualifying.") - 63
return 1 - 64
- 65
- 66
if __name__ == "__main__": - 67
sys.exit(main())