Skip to content

Read the session from a signed-in Firefox-family browser - #2

Merged
curbol merged 1 commit into
mainfrom
curbol/browser-session
Aug 23, 2026
Merged

Read the session from a signed-in Firefox-family browser#2
curbol merged 1 commit into
mainfrom
curbol/browser-session

Conversation

@curbol

@curbol curbol commented Aug 23, 2026

Copy link
Copy Markdown
Owner

What

Adds a third session source: a signed-in Firefox-family browser. session_source = "browser"
(or --session browser) reads Gecko's session store instead of a pasted curl command.

--session also now accepts a browser profile directory or a recovery.jsonlz4 directly, and
works out what any path is by reading it rather than by configuration — a session store is
identified by its mozLz40\0 magic, a curl paste by its structure.

Why

The paste exists because LS is a session cookie and cookies.sqlite never holds it. That
measurement was right and the conclusion drawn from it was wrong: Gecko keeps a session
store
so it can restore a session, and that file holds the cookies of every host the session
touched — LS among them. Verified against a real profile: LS + _csrf out of
recovery.jsonlz4 return HTTP 200 with the full owned list.

Two properties decide what this can promise, both measured rather than assumed:

  • Not tab-scoped. On the profile tested, 156 of 169 cookie hosts had no tab open anywhere
    in the session, assetstore.unity.com among them. The credential outlives the tab and lasts
    as long as the browsing session, so this is not "keep a tab open".
  • It lags. The file is rewritten periodically, not on every cookie change, so a sign-in
    takes seconds to show up.

Chromium keeps session cookies in an encrypted SQLite database instead, so it is out of scope
and the docs say so.

Notable details

  • Profile discovery reads installs.ini before the Default=1 flag in profiles.ini.
    They disagree on the machine this was built against, and only the profile installs.ini
    names has a session store at all. Preferring the flag finds an empty profile and reports no
    session on a machine where there plainly is one.
  • The mozlz4 decoder is ~40 lines rather than a dependency, in a module that otherwise has
    one. It is bounds-checked throughout because it parses a file another program wrote, and it
    caps the size the header claims so a corrupt header cannot become a huge allocation.
  • The session store is read narrowly. It carries credentials for every host the browsing
    session touched, so it is filtered to the unity.com family inside internal/session
    before anything leaves the package, and no cookie value is ever logged — every error and
    diagnostic carries paths and cookie names only.

Testing

go test -race ./... green across 14 packages; go vet and gofmt -l clean.

New tests cover the decoder against overlapping matches, extended match lengths, truncated
blocks, a header that overstates its payload, and one that claims a gigabyte; that only
unity.com cookies survive a jar containing other sites; that installs.ini beats the
Default=1 flag; that a profile without the credential is skipped rather than fatal; and that
a path is identified by content.

One test is opt-in and skipped by default, since it needs a live credential store:

UNITY_SYNC_REAL_SESSIONSTORE=~/.config/zen/<profile>/sessionstore-backups/recovery.jsonlz4 \
  go test ./internal/session/

Run live against the real 176-asset account, all three paths:

  • session_source = "browser" in config.toml — no paste anywhere, reports which profile it read
  • --session <profile dir> pointed straight at a Zen profile
  • --session session.curl, the existing paste, unchanged

Release Notes

You can now point unity-sync at your browser instead of pasting a session. Set
session_source = "browser" in config.toml, sign in to the Asset Store in Firefox, Zen,
LibreWolf, Waterfox or Floorp, and unity-sync reads the session from there — no re-pasting when
it expires. Pasting still works exactly as before.

The paste exists because LS is a session cookie and cookies.sqlite never holds
it. That was the right measurement and the wrong conclusion: Gecko's session
store keeps the cookies of every host a browsing session touched, so it can
restore them, and LS is in there. Measured on a real profile, LS and _csrf out
of recovery.jsonlz4 return HTTP 200 and the full owned list.

Two things decide what that can promise, both measured rather than assumed. The
jar is not tab-scoped: on the profile tested, 156 of 169 cookie hosts had no tab
open anywhere in the session, assetstore.unity.com among them, so the credential
outlives the tab and lasts as long as the browsing session. And the file is
rewritten periodically, so it lags a sign-in by seconds.

`session_source = "browser"` sweeps the known Gecko roots. A path still works
and now also accepts a profile directory or a recovery.jsonlz4 directly, so a
browser this does not know where to find is reachable by pointing at it. Which
kind of source a path is gets decided by reading it — a session store by its
mozLz40 magic — rather than by asking the user to declare it.

Profile discovery reads installs.ini before the Default=1 flag in profiles.ini.
They disagree on the machine this was built against, and only the profile
installs.ini names has a session store at all; preferring the flag finds an
empty profile and reports no session where there plainly is one.

The mozlz4 decoder is ~40 lines of LZ4 block decoding rather than a dependency,
bounds-checked throughout because it parses a file another program wrote, with a
ceiling on the size the header claims. Tests cover overlapping matches, extended
lengths, truncation, and a lying header; an opt-in test decodes a real profile,
skipped by default since that file is a live credential store.

That store carries credentials for every host the session touched, so it is
filtered to the unity.com family inside internal/session before anything leaves
the package, and no value is ever logged. Chromium encrypts its session cookies
elsewhere and is out of scope.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012LiuqQ1Kt5Ak2YgAxuzUZV
@curbol
curbol merged commit 7c32acf into main Aug 23, 2026
1 check passed
@curbol
curbol deleted the curbol/browser-session branch August 23, 2026 05:10
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