sweedworks

← all sources

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.

"""Any cookie set while loading the site, read from Chrome's own cookie store.

Every page footer says "no cookies". checklive.py only ever checked for a
Set-Cookie *header* — but a script can set one with document.cookie, and
Cloudflare runs a fingerprinting script on every page here. So the claim was
verified in the one place it was least likely to fail.

Run shot.sh against a page first (ideally after deleting the profile, so the
store starts empty), then:

    python3 checkcookies.py
"""

import os
import sqlite3
import sys

PROFILE = "/var/www/sweedworks/.chrome-home"
STORE = os.path.join(PROFILE, "Default", "Cookies")


def main():
    if not os.path.exists(STORE):
        print(f"no cookie store at {STORE}")
        print("Chrome did not create one, which means nothing tried to set a "
              "cookie.")
        return 0

    # Copy first: the store may be locked, and we must not modify it.
    tmp = "/tmp/claude-996/cookies-copy.sqlite"
    with open(STORE, "rb") as src, open(tmp, "wb") as dst:
        dst.write(src.read())

    con = sqlite3.connect(tmp)
    try:
        rows = con.execute(
            "SELECT host_key, name, path, is_secure, is_httponly, "
            "has_expires, is_persistent FROM cookies").fetchall()
    except sqlite3.DatabaseError as e:
        print(f"could not read cookie store: {e}")
        return 1
    finally:
        con.close()

    if not rows:
        print(f"cookie store exists ({os.path.getsize(STORE)} bytes) but holds "
              f"no cookies.")
        print("Nothing set a cookie while loading the site.")
        return 0

    print(f"{len(rows)} cookie(s) present:")
    for host, name, path, secure, httponly, has_exp, persistent in rows:
        flags = []
        if secure:
            flags.append("secure")
        if httponly:
            flags.append("httpOnly")
        flags.append("persistent" if persistent else "session")
        print(f"  {host:<24} {name:<24} {path:<10} {', '.join(flags)}")

    print()
    print("The footer says 'no cookies'. That is now false, or needs qualifying.")
    return 1


if __name__ == "__main__":
    sys.exit(main())