Skip to content

feat(firefox): decrypt profiles with a primary password - #704

Open
moonD4rk wants to merge 4 commits into
feat/configurable-storage-value-limitfrom
feat/firefox-primary-password
Open

moonD4rk wants to merge 4 commits into
feat/configurable-storage-value-limitfrom
feat/firefox-primary-password

Conversation

@moonD4rk

@moonD4rk moonD4rk commented Nov 18, 2026 •

Copy link
Copy Markdown
Owner

Closes #109 — decrypt Firefox profiles protected by a Primary Password.

Stacked on #703 (base branch feat/configurable-storage-value-limit); review that first. GitHub retargets this to main once #703 merges.

What

  • New --firefox-pw / --firefox-pw-stdin on dump (mirrors --keychain-pw). The password rides on browser.Input, and only the dump path supplies it (restore is Chromium-only).
  • Key derivation follows NSS's password key: SHA1(globalSalt ∥ password), or SHA-384 when the global salt is 48 bytes, which current NSS writes for a newly set primary password (Firefox 159 does).
  • Each profile is tried with the empty password first; the given one is read only when that fails, so one run can mix the rare protected profile with the many unprotected ones. A profile that needs a password but got none errors with a message naming the flag.
  • --firefox-pw-stdin reads stdin once and reuses it for every protected profile; it is mutually exclusive with --keychain-pw-stdin, which would read the same stream.
  • A key4.db whose password check will not parse is reported as corrupt, not as a wrong password.

No prompt

A missing --firefox-pw means the empty password, so the common no-password profile never triggers a prompt; a profile that actually needs one errors and names the flag (shown with -v; the table reports "not recovered").

Validated with real Firefox 159 (macOS, throwaway profiles)

Two profiles with a primary password and one without, each holding one fake login:

  • no flag: the unprotected profile decrypts; the protected ones report pass it with --firefox-pw
  • wrong password: the protected ones report primary password is incorrect
  • right password via --firefox-pw and via --firefox-pw-stdin: all three decrypt
  • --firefox-pw-stdin together with --keychain-pw-stdin: rejected

Test

go test ./... green; a known-answer test replays a real Firefox 159 primary-password key4.db check; unit tests cover password selection (right / missing / wrong / corrupt check, and no read when the empty password fits) an end-to-end retrieveMasterKey over a 48-byte-salt key4.db + logins.json fixture; and an Execute-level test that two protected profiles share one password read; the existing Firefox e2e tests keep the empty-password path; golangci-lint clean; cross-compiles linux/windows/darwin.

Firefox key derivation assumed an empty primary password. Add
--firefox-pw / --firefox-pw-stdin; each profile is tried with the empty
password first, then the given one, so one run can mix protected and
unprotected profiles.
--firefox-pw-stdin read a fresh line per profile, so only the first got
the password; read it once and lazily, and make it exclusive with
--keychain-pw-stdin. A key4.db that will not parse is a corrupt DB, not
a wrong password. Add positive and end-to-end primary-password tests.
@moonD4rk
moonD4rk force-pushed the feat/firefox-primary-password branch from 57b0fdd to b0c01ff Compare November 18, 2026 09:23
NSS gives a newly set primary password a 48-byte salt and SHA-384, so real
Firefox 159 profiles failed the password check even with the right password.
It bypassed DumpOptions, read once inside cmd, and used []byte where the
keychain password uses string; Execute now owns the once-per-run read.
@moonD4rk
moonD4rk added this pull request to stack #706 November 18, 2026 14:07
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