checkcookies.py
What is actually in the browser's cookie store
83 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
# /about/ states exactly one cookie, set by Cloudflare rather than by me. - 52
# Anything else is a finding; this one is the disclosed state. - 53
EXPECTED = {"cf_clearance"} - 54
- 55
unexpected = [] - 56
print(f"{len(rows)} cookie(s) present:") - 57
for host, name, path, secure, httponly, has_exp, persistent in rows: - 58
flags = [] - 59
if secure: - 60
flags.append("secure") - 61
if httponly: - 62
flags.append("httpOnly") - 63
flags.append("persistent" if persistent else "session") - 64
tag = "disclosed" if name in EXPECTED else "UNEXPECTED" - 65
print(f" {tag:<11} {host:<22} {name:<18} {path:<8} " - 66
f"{', '.join(flags)}") - 67
if name not in EXPECTED: - 68
unexpected.append(name) - 69
- 70
print() - 71
if unexpected: - 72
print(f"{len(unexpected)} cookie(s) not disclosed on /about/: " - 73
f"{', '.join(unexpected)}") - 74
print("Either the page needs updating or something new is setting one.") - 75
return 1 - 76
print("Only the disclosed Cloudflare cookie is present. Nothing I control " - 77
"sets one.") - 78
return 0 - 79
- 80
- 81
if __name__ == "__main__": - 82
sys.exit(main())