Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of cookies in Chromium cookie database versions >=24. #73

Merged
merged 7 commits into from
Oct 31, 2024
10 changes: 9 additions & 1 deletion src/pycookiecheat/chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def clean(decrypted: bytes) -> str:


def chrome_decrypt(
encrypted_value: bytes, key: bytes, init_vector: bytes
encrypted_value: bytes, key: bytes, init_vector: bytes, cookie_database_version: int
chrisgavin marked this conversation as resolved.
Show resolved Hide resolved
) -> str:
"""Decrypt Chrome/Chromium's encrypted cookies.

Expand All @@ -88,6 +88,10 @@ def chrome_decrypt(
decryptor = cipher.decryptor()
decrypted = decryptor.update(encrypted_value) + decryptor.finalize()

if cookie_database_version >= 24:
# Cookies in database version 24 and later include a SHA256 hash of the domain to the start of the encrypted value.
chrisgavin marked this conversation as resolved.
Show resolved Hide resolved
decrypted = decrypted[32:]

return clean(decrypted)


Expand Down Expand Up @@ -310,6 +314,9 @@ def chrome_cookies(

conn.row_factory = sqlite3.Row

sql = "select value from meta where key = 'version';"
cookie_database_version = int(conn.execute(sql).fetchone()[0])

# Check whether the column name is `secure` or `is_secure`
secure_column_name = "is_secure"
for (
Expand Down Expand Up @@ -344,6 +351,7 @@ def chrome_cookies(
row["encrypted_value"],
key=enc_key,
init_vector=config["init_vector"],
cookie_database_version=cookie_database_version,
)
del row["encrypted_value"]
cookies.append(Cookie(**row))
Expand Down
Loading