Skip to content

fix(auth): find cookies in Chromium, not just Chrome - #23

Open
ozanboz wants to merge 1 commit into
jackwener:mainfrom
ozanboz:fix/chromium-cookie-extraction
Open

ozanboz wants to merge 1 commit into
jackwener:mainfrom
ozanboz:fix/chromium-cookie-extraction

Conversation

@ozanboz

@ozanboz ozanboz commented Sep 10, 2026 •

Copy link
Copy Markdown

Problem

rdt login reports "No Reddit cookies found" on a machine that is logged into
reddit.com, because the browser is Chromium, not Chrome. browser_cookie3.chromium
is a separate entry point (~/.config/chromium vs ~/.config/google-chrome) and it was
missing from both extraction paths. Chromium is the packaged default on Arch, Omarchy
and other distros, so the login flow is unusable there.

$ sqlite3 ~/.config/chromium/Default/Cookies \
    "select name from cookies where host_key like '%reddit%'"
reddit_session
token_v2
loid
...
$ python -c "import browser_cookie3 as bc; print(len(list(bc.chrome(domain_name='reddit.com'))))"
0
$ python -c "import browser_cookie3 as bc; print(len(list(bc.chromium(domain_name='reddit.com'))))"
11

Second bug in the same code: _extract_subprocess broke on the first browser that
returned any cookie, so a browser holding only tracking cookies (csv, edgebucket)
shadowed the one that actually had reddit_session — the caller then rejected the jar
via REQUIRED_COOKIES and reported "no cookies found" while a valid session sat in the
next browser on the list. It now breaks on REQUIRED_COOKIES, same as _extract_direct.

Change

Net -3 lines. Adding chromium made the browser lists exceed the 120-char ruff
limit, so import browser_cookie3 as bc keeps them on one line instead of wrapping
them; the subprocess script's accumulate-then-check dance collapses into breaking on
the required cookie, and required is derived from REQUIRED_COOKIES rather than
duplicating the rule.

Verification

Arch/Omarchy, Chromium 152, --password-store=gnome-libsecret:

$ rm ~/.config/rdt-cli/credential.json && rdt login
✅ Already authenticated        # source: browser:subprocess, 11 cookies, reddit_session present

$ rdt search "arch linux btrfs snapper" -n 1
title:     "Scary Btrfs – Is Btrfs oversold? What filesystem do Arch users prefer?"
subreddit: archlinux
score:     89

Authenticated response (modhash returned), so it is a real logged-in session.

$ uv run ruff check rdt_cli/auth.py    # All checks passed!
$ uv run ruff format --check rdt_cli/auth.py
$ uv run pytest -q                     # 123 passed, 66 deselected

No new dependency: chromium ships in the browser-cookie3 package already in use.

browser_cookie3.chromium was missing from both extraction paths, so
`rdt login` failed with "No Reddit cookies found" on systems whose
browser is Chromium rather than Chrome — the default on Arch, Omarchy
and other distros — even with a valid logged-in session.

The subprocess path also broke on the first browser that returned *any*
cookie, so a browser holding only tracking cookies (csv, edgebucket)
shadowed the one that actually had reddit_session; the caller then
rejected the result and reported "no cookies found". It now breaks on
REQUIRED_COOKIES, matching _extract_direct.

Net -3 lines: the accumulate-then-check dance is gone, and `import
browser_cookie3 as bc` keeps the longer browser list on one line.
@ozanboz
ozanboz force-pushed the fix/chromium-cookie-extraction branch from 746c832 to 9ab71b7 Compare September 10, 2026 22:25
caioniehues added a commit to caioniehues/rdt-cli that referenced this pull request Nov 28, 2026
Auth
- Find Reddit cookies in every profile of Firefox/LibreWolf (including the
  XDG ~/.config/mozilla/firefox location of Firefox 147+, snap, flatpak) and
  Chrome/Chromium/Brave/Edge/Vivaldi. Firefox DBs are read from a copy that
  includes the -wal file, so fresh logins are seen and the browser lock is
  avoided. Only logged-in sessions count (reddit_session, or a token_v2 JWT
  with sub=user); anonymous jars are skipped. Drops the uv subprocess path.
  Covers upstream jackwener#9, jackwener#16, jackwener#23.
- RDT_COOKIE / RDT_SESSION / RDT_MODHASH env auth; public commands no longer
  extract browser cookies on their own (upstream jackwener#17).
- rdt login reports the source and no longer claims "already authenticated"
  after silently extracting.

Upstream fixes
- search falls back to api.reddit.com when search.json is 403 (jackwener#27, jackwener#28).
- comment sends api_type/thing_id/text and raises on json.errors (jackwener#14).

Reading posts
- read/upvote/save/comment accept reddit.com and redd.it post URLs.
- read/show --markdown: post + full comment tree as Markdown; --article
  appends the linked page of link posts via the defuddle CLI.
- morechildren requests are batched at 100 IDs (was 414 URI Too Long); when
  Reddit blocks the API (403), --expand-more warns and keeps loaded comments.
- Error codes are no longer swallowed as Rich markup.

Tests
- Unit tests no longer write to the real ~/.config/rdt-cli.
- New tests for browser discovery, env auth, Markdown, URL parsing, batching.
ticoAg added a commit to ticoAg/rdt-cli that referenced this pull request Nov 28, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant