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: Firefox cookie extraction falls back to non-default profiles on multi-profile setups (#521)

SAI MOHANEESHb034c7373b1e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7478c45f..22185e95 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- First-run setup wizard in SKILL.md now references the existing Python setup wizard (`last30days.py setup`) instead of the missing `nux-wizard.md` file, so first-run setup actually runs on new installs. ([#574](https://github.com/mvanhorn/last30days-skill/issues/574))
- `check-config.sh` no longer exits 1 on the ScrapeCreators-configured path when no prior run exists (empty `LAST_RUN_LINE`) — swapped `&&` guard for an `if` block that always exits cleanly ([#463](https://github.com/mvanhorn/last30days-skill/issues/463))
- `check-config.sh` no longer exits 1 when a `.env` value contains an unbalanced quote — replaced `xargs` (which interprets quotes) with `sed` for whitespace trimming in `load_env_vars` ([#506](https://github.com/mvanhorn/last30days-skill/issues/506))
+- Firefox cookie extraction now falls back to scanning non-default profiles when the default profile has no matching X cookies, fixing multi-profile setups where login lives on a non-default profile ([#498](https://github.com/mvanhorn/last30days-skill/issues/498))
- `subproc.py` `run_with_timeout()` now guards `os.killpg` / `os.getpgid` with `hasattr`, preventing an uncaught `AttributeError` crash when a subprocess times out on Windows where these functions don't exist ([#527](https://github.com/mvanhorn/last30days-skill/issues/527))
- Entity-grounding rerank demotion now keys on the head token of the primary entity instead of requiring the full multi-word phrase as a contiguous substring. A high-engagement on-entity item (e.g. a 323-pt HN thread titled "Stripe is friendly to 'friendly fraud'") is no longer demoted to score 0 on a `Stripe payments` query just because it lacks the trailing search-hint word. The intended demotion still fires for items that never name the brand at all. The keyless Reddit comment-enrichment slot selection (`_slot_priority`), which mirrors this signal, was updated to the same head-token grounding so the two paths stay consistent.
- `--plan` / `--competitors-plan` file reads now specify `encoding="utf-8"` and catch `UnicodeDecodeError`, preventing crashes on non-ASCII content like accented entity names on Windows (cp1252). `check_perms()` in `check-config.sh` now skips the POSIX 600-permission check on MSYS/MinGW/Cygwin where `stat` runs in noacl mode. `skill_meta.py` `read_skill_version()` now passes `encoding="utf-8"` so SKILL.md emoji doesn't break version detection on Windows. ([#549](https://github.com/mvanhorn/last30days-skill/issues/549))
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index d7cd4137..70a73225 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -61,4 +61,5 @@ v3 has durable watchlist with multi-source storage and extended time windows.
- [@23241a6749](https://github.com/23241a6749) - Windows cp1252 fixes: utf-8 plan-file reads, skill_meta version-detection encoding, MSYS noacl permission check skip ([#549](https://github.com/mvanhorn/last30days-skill/pull/549)); first-run setup wizard fix: SKILL.md references existing Python setup wizard instead of missing nux-wizard.md ([#574](https://github.com/mvanhorn/last30days-skill/pull/574))
- [@23241a6749](https://github.com/23241a6749) - check-config.sh clean-exit on missing last-run.json ([#463](https://github.com/mvanhorn/last30days-skill/issues/463))
- [@23241a6749](https://github.com/23241a6749) - check-config.sh xargs unterminated quote fix ([#506](https://github.com/mvanhorn/last30days-skill/issues/506))
+- [@23241a6749](https://github.com/23241a6749) - Firefox multi-profile cookie fallback ([#498](https://github.com/mvanhorn/last30days-skill/issues/498))
- [@23241a6749](https://github.com/23241a6749) - Windows subprocess timeout fix: guard os.killpg/os.getpgid with hasattr in subproc.py ([#527](https://github.com/mvanhorn/last30days-skill/issues/527))
diff --git a/skills/last30days/scripts/lib/cookie_extract.py b/skills/last30days/scripts/lib/cookie_extract.py
index a9b5f75c..806c81af 100644
--- a/skills/last30days/scripts/lib/cookie_extract.py
+++ b/skills/last30days/scripts/lib/cookie_extract.py
@@ -200,12 +200,36 @@ def _query_cookies_db(
def _try_firefox_dir(profiles_dir: Path, domain: str, cookie_names: List[str]) -> Optional[Dict[str, str]]:
- """Try to extract cookies from a Firefox profiles directory."""
- profile_path = _find_default_profile(profiles_dir)
- if profile_path is None:
- logger.debug("No Firefox profile found in %s", profiles_dir)
- return None
- return _query_cookies_db(profile_path / "cookies.sqlite", domain, cookie_names)
+ """Try to extract cookies from a Firefox profiles directory.
+
+ Tries the default profile first, then falls back to scanning all
+ profiles for matching cookies. This handles multi-profile setups
+ where the user is logged into x.com on a non-default profile.
+ """
+ default_profile = _find_default_profile(profiles_dir)
+ profiles_tried = 0
+ if default_profile is not None:
+ result = _query_cookies_db(default_profile / "cookies.sqlite", domain, cookie_names)
+ if result is not None:
+ return result
+ profiles_tried = 1
+ # Fallback: scan every profile directory for matching cookies
+ try:
+ for child in sorted(profiles_dir.iterdir()):
+ if not child.is_dir():
+ continue
+ if default_profile is not None and child == default_profile:
+ continue
+ db = child / "cookies.sqlite"
+ if db.is_file():
+ result = _query_cookies_db(db, domain, cookie_names)
+ if result is not None:
+ return result
+ profiles_tried += 1
+ except OSError:
+ pass
+ logger.debug("No matching cookies found in %d Firefox profile(s)", profiles_tried)
+ return None
def extract_firefox_cookies(
diff --git a/tests/test_cookie_extract.py b/tests/test_cookie_extract.py
index d63d9817..cc694bf1 100644
--- a/tests/test_cookie_extract.py
+++ b/tests/test_cookie_extract.py
@@ -248,6 +248,84 @@ class TestExtractFirefoxCookies:
assert result is not None
assert result["auth_token"] == "fallback_token"
+ 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(
+ profiles={
+ "aaa111.default": [
+ (".example.com", "session", "sess_other"),
+ ],
+ "bbb222.release": [
+ (".x.com", "auth_token", "tok_nondefault"),
+ (".x.com", "ct0", "ct0_nondefault"),
+ ],
+ },
+ profiles_ini=textwrap.dedent("""\
+ [General]
+ StartWithLastProfile=1
+
+ [Profile0]
+ Name=default
+ IsRelative=1
+ Path=aaa111.default
+ Default=1
+
+ [Profile1]
+ Name=release
+ IsRelative=1
+ Path=bbb222.release
+ """),
+ )
+
+ 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"] == "tok_nondefault"
+ assert result["ct0"] == "ct0_nondefault"
+
+ def test_multiple_profiles_none_have_cookies(self, mock_firefox_env):
+ """Returns None when no profile has matching cookies."""
+ profiles_dir = mock_firefox_env(
+ profiles={
+ "aaa111.default": [
+ (".example.com", "session", "sess_a"),
+ ],
+ "bbb222.release": [
+ (".other.com", "other", "val_b"),
+ ],
+ },
+ profiles_ini=textwrap.dedent("""\
+ [General]
+ StartWithLastProfile=1
+
+ [Profile0]
+ Name=default
+ IsRelative=1
+ Path=aaa111.default
+ Default=1
+
+ [Profile1]
+ Name=release
+ IsRelative=1
+ Path=bbb222.release
+ """),
+ )
+
+ with patch(
+ "lib.cookie_extract._get_firefox_profiles_dir",
+ return_value=profiles_dir,
+ ), patch(
+ "lib.cookie_extract._is_wsl",
+ return_value=False,
+ ):
+ result = extract_firefox_cookies(".x.com", ["auth_token", "ct0"])
+
+ assert result is None
+
class TestExtractCookiesAuto:
"""Tests for extract_cookies with browser='auto'."""