Skip to content

AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary

fix(cookies): parse Windows Firefox profiles.ini as UTF-16 (#1068)

Saurabh40b486071f8a
diff --git a/changelog.d/1067.fixed.md b/changelog.d/1067.fixed.md
new file mode 100644
index 00000000..020f7520
--- /dev/null
+++ b/changelog.d/1067.fixed.md
@@ -0,0 +1 @@
+Windows Firefox `FROM_BROWSER` X auth no longer dies on a UTF-16 `profiles.ini` (`UnicodeDecodeError` used to skip the fallback and kill the only keyless X route).
diff --git a/skills/last30days/scripts/lib/cookie_extract.py b/skills/last30days/scripts/lib/cookie_extract.py
index 74999409..b2348a33 100644
--- a/skills/last30days/scripts/lib/cookie_extract.py
+++ b/skills/last30days/scripts/lib/cookie_extract.py
@@ -86,6 +86,16 @@ def _get_firefox_profiles_dir() -> Optional[Path]:
return path if path.is_dir() else None
+def _load_profiles_ini(ini_path: Path) -> configparser.ConfigParser:
+ """Parse Firefox profiles.ini, retrying UTF-16 LE used on Windows (#1067)."""
+ config = configparser.ConfigParser()
+ try:
+ config.read(str(ini_path), encoding="utf-8")
+ except UnicodeDecodeError:
+ config.read(str(ini_path), encoding="utf-16")
+ return config
+
+
def _find_default_profile(profiles_dir: Path) -> Optional[Path]:
"""Parse profiles.ini to find the default profile directory.
@@ -96,8 +106,7 @@ def _find_default_profile(profiles_dir: Path) -> Optional[Path]:
if ini_path.is_file():
try:
- config = configparser.ConfigParser()
- config.read(str(ini_path), encoding="utf-8")
+ config = _load_profiles_ini(ini_path)
# First pass: Install* section (Firefox >= 67 format, takes priority)
for section in config.sections():
@@ -118,7 +127,7 @@ def _find_default_profile(profiles_dir: Path) -> Optional[Path]:
resolved = _resolve_profile_path(profiles_dir, config, section)
if resolved and resolved.is_dir():
return resolved
- except (configparser.Error, OSError) as exc:
+ except (configparser.Error, OSError, UnicodeDecodeError) as exc:
logger.debug("Failed to parse profiles.ini: %s", exc)
# Fallback: scan directory for anything that looks like a profile
diff --git a/tests/test_cookie_extract.py b/tests/test_cookie_extract.py
index 0346240e..e6b8ce2a 100644
--- a/tests/test_cookie_extract.py
+++ b/tests/test_cookie_extract.py
@@ -281,6 +281,39 @@ class TestExtractFirefoxCookies:
assert result is not None
assert result["auth_token"] == "fallback_token"
+ def test_utf16_profiles_ini_uses_install_default(self, mock_firefox_env):
+ """Firefox on Windows writes UTF-16 LE profiles.ini (#1067)."""
+ default_profile = "en3ndvop.default-release"
+ decoy = "aaa111.decoy"
+ profiles_dir = mock_firefox_env(
+ default_profile=default_profile,
+ profiles={
+ decoy: [
+ (".x.com", "auth_token", "decoy_token"),
+ ],
+ default_profile: [
+ (".x.com", "auth_token", "utf16_token"),
+ (".x.com", "ct0", "utf16_ct0"),
+ ],
+ },
+ )
+ ini = textwrap.dedent(f"""\
+ [Install308046B0AF4A39CB]
+ Default={default_profile}
+ Locked=1
+ """)
+ (profiles_dir / "profiles.ini").write_bytes(ini.encode("utf-16"))
+
+ with patch(
+ "lib.cookie_extract._get_firefox_profiles_dir",
+ return_value=profiles_dir,
+ ):
+ result = extract_firefox_cookies(".x.com", ["auth_token", "ct0"])
+
+ assert result is not None
+ assert result["auth_token"] == "utf16_token"
+ assert result["ct0"] == "utf16_ct0"
+
def test_non_default_profile_with_cookies(self, mock_firefox_env):
"""Falls back to non-default profile when default has no X cookies."""
profiles_dir = mock_firefox_env(