[cookies:firefox] support using domain + container filters together

This commit is contained in:
Mike Fährmann
2024-09-16 14:47:23 +02:00
parent a9dc7a6f98
commit 73f833d08a
2 changed files with 17 additions and 11 deletions

View File

@@ -513,8 +513,8 @@ Description
* The first entry is the browser name
* The optional second entry is a profile name or an absolute path to a profile directory
* The optional third entry is the keyring to retrieve passwords for decrypting cookies from
* The optional fourth entry is a (Firefox) container name (``"none"`` for only cookies with no container)
* The optional fifth entry is the domain to extract cookies for. Prefix it with a dot ``.`` to include cookies for subdomains. Has no effect when also specifying a container.
* The optional fourth entry is a (Firefox) container name (``"none"`` for only cookies with no container (default))
* The optional fifth entry is the domain to extract cookies for. Prefix it with a dot ``.`` to include cookies for subdomains.
.. code:: json

View File

@@ -50,21 +50,27 @@ def load_cookies_firefox(cookiejar, profile=None, container=None, domain=None):
sql = ("SELECT name, value, host, path, isSecure, expiry "
"FROM moz_cookies")
parameters = ()
conditions = []
parameters = []
if container_id is False:
sql += " WHERE NOT INSTR(originAttributes,'userContextId=')"
conditions.append("NOT INSTR(originAttributes,'userContextId=')")
elif container_id:
sql += " WHERE originAttributes LIKE ? OR originAttributes LIKE ?"
conditions.append(
"originAttributes LIKE ? OR originAttributes LIKE ?")
uid = "%userContextId={}".format(container_id)
parameters = (uid, uid + "&%")
elif domain:
parameters += (uid, uid + "&%")
if domain:
if domain[0] == ".":
sql += " WHERE host == ? OR host LIKE ?"
parameters = (domain[1:], "%" + domain)
conditions.append("host == ? OR host LIKE ?")
parameters += (domain[1:], "%" + domain)
else:
sql += " WHERE host == ? OR host == ?"
parameters = (domain, "." + domain)
conditions.append("host == ? OR host == ?")
parameters += (domain, "." + domain)
if conditions:
sql = "{} WHERE ( {} )".format(sql, " ) AND ( ".join(conditions))
set_cookie = cookiejar.set_cookie
for name, value, domain, path, secure, expires in db.execute(