From cebfa97ed693e46191e099b7b502377a40697d98 Mon Sep 17 00:00:00 2001 From: Roger Date: Thu, 29 Oct 2026 14:10:44 +0800 Subject: [PATCH] fix(chromium): export Yandex rows without the data key (#666) Without the data key the Yandex stores exported nothing, unlike every other store, so a key failure or a master password lost the rows and list --detail, which reads no key, counted 0. --- .../browser/chromium/extract_creditcard.go | 9 ++-- .../chromium/extract_creditcard_test.go | 9 +++- internal/browser/chromium/extract_password.go | 9 ++-- .../browser/chromium/extract_password_test.go | 41 +++++++++++++++---- rfcs/000-goals-and-constraints.md | 2 +- rfcs/008-output-and-export.md | 1 + rfcs/011-testing-and-quality.md | 1 + rfcs/012-migration-roadmap.md | 1 + 8 files changed, 54 insertions(+), 19 deletions(-) diff --git a/internal/browser/chromium/extract_creditcard.go b/internal/browser/chromium/extract_creditcard.go index 1c486ae..df62b63 100644 --- a/internal/browser/chromium/extract_creditcard.go +++ b/internal/browser/chromium/extract_creditcard.go @@ -65,10 +65,7 @@ func extractCreditCards(masterKeys masterkey.Set, path string, out browser.Colle // extractYandexCreditCards reads the records table (not Chromium's credit_cards). AAD = guid. func extractYandexCreditCards(masterKeys masterkey.Set, path string, out browser.Collector) error { - dataKey, err := loadYandexDataKey(path, masterKeys[masterkey.V10]) - if err != nil { - return err - } + dataKey, keyErr := loadYandexDataKey(path, masterKeys[masterkey.V10]) cards, err := sqlitex.QueryRows(path, false, yandexCreditCardQuery, func(rows *sql.Rows) (record.CreditCard, error) { @@ -91,6 +88,10 @@ func extractYandexCreditCards(masterKeys masterkey.Set, path string, out browser ExpYear: public.ExpireDateYear, NickName: public.CardTitle, } + if dataKey == nil { + out.Fail(fmt.Errorf("yandex: card %s: %w", guid, keyErr)) + return entry, nil + } plaintext, err := crypto.AESGCMDecryptBlob(dataKey, privateData, yandexCardAAD(guid, nil)) if err != nil { diff --git a/internal/browser/chromium/extract_creditcard_test.go b/internal/browser/chromium/extract_creditcard_test.go index 8c9ad21..c615413 100644 --- a/internal/browser/chromium/extract_creditcard_test.go +++ b/internal/browser/chromium/extract_creditcard_test.go @@ -103,8 +103,13 @@ func TestExtractYandexCreditCards_WrongMasterKey(t *testing.T) { yandexCreditCard{GUID: "g1", FullCardNumber: "4111"}, ) - err := extractYandexCreditCards(masterkey.Set{masterkey.V10: wrongKey}, path, &testCollector{}) - require.Error(t, err) + var out testCollector + require.NoError(t, extractYandexCreditCards(masterkey.Set{masterkey.V10: wrongKey}, path, &out)) + cards := collected[record.CreditCard](t, &out) + require.Len(t, cards, 1, "the card exports without its number") + assert.Equal(t, "g1", cards[0].GUID) + assert.Empty(t, cards[0].Number) + assert.Len(t, out.fails, 1) } func TestYandexCardAAD(t *testing.T) { diff --git a/internal/browser/chromium/extract_password.go b/internal/browser/chromium/extract_password.go index 1f69403..89dec95 100644 --- a/internal/browser/chromium/extract_password.go +++ b/internal/browser/chromium/extract_password.go @@ -54,10 +54,7 @@ func extractPasswordsWithQuery(masterKeys masterkey.Set, path string, store reco // extractYandexPasswords walks Ya Passman Data. // Note: URL column is origin_url — it's what the per-row AAD is computed over (not action_url). func extractYandexPasswords(masterKeys masterkey.Set, path string, out browser.Collector) error { - dataKey, err := loadYandexDataKey(path, masterKeys[masterkey.V10]) - if err != nil { - return err - } + dataKey, keyErr := loadYandexDataKey(path, masterKeys[masterkey.V10]) logins, err := sqlitex.QueryRows(path, false, yandexLoginQuery, func(rows *sql.Rows) (record.Login, error) { @@ -73,6 +70,10 @@ func extractYandexPasswords(masterKeys masterkey.Set, path string, out browser.C CreatedAt: timeconv.Chromium(created), Store: record.StoreLocal, } + if dataKey == nil { + out.Fail(fmt.Errorf("yandex: password for %s: %w", originURL, keyErr)) + return entry, nil + } aad := yandexLoginAAD(originURL, usernameElem, usernameVal, passwordElem, signonRealm, nil) plaintext, err := crypto.AESGCMDecryptBlob(dataKey, passwordValue, aad) if err != nil { diff --git a/internal/browser/chromium/extract_password_test.go b/internal/browser/chromium/extract_password_test.go index 6c6c8c3..abde67a 100644 --- a/internal/browser/chromium/extract_password_test.go +++ b/internal/browser/chromium/extract_password_test.go @@ -90,7 +90,7 @@ func TestExtractYandexPasswords(t *testing.T) { assert.Equal(t, "hunter2", got[0].Password) } -func TestExtractYandexPasswords_MasterPasswordSkipped(t *testing.T) { +func TestExtractYandexPasswords_MasterPasswordKeepsTheLogins(t *testing.T) { masterKey := bytes.Repeat([]byte{0x11}, 32) dataKey := bytes.Repeat([]byte{0x22}, 32) @@ -103,9 +103,31 @@ func TestExtractYandexPasswords_MasterPasswordSkipped(t *testing.T) { ) var out testCollector - err := extractYandexPasswords(masterkey.Set{masterkey.V10: masterKey}, path, &out) - require.ErrorIs(t, err, errYandexMasterPasswordSet) - assert.Empty(t, out.records, "a master-password profile yields no logins") + require.NoError(t, extractYandexPasswords(masterkey.Set{masterkey.V10: masterKey}, path, &out)) + logins := collected[record.Login](t, &out) + require.Len(t, logins, 1) + assert.Equal(t, "alice", logins[0].Username) + assert.Empty(t, logins[0].Password) + require.Len(t, out.fails, 1) + assert.ErrorIs(t, out.fails[0], errYandexMasterPasswordSet) +} + +func TestExtractYandexPasswords_WithoutAKeyKeepsTheLogins(t *testing.T) { + masterKey := bytes.Repeat([]byte{0x11}, 32) + dataKey := bytes.Repeat([]byte{0x22}, 32) + path := setupYandexPasswordDB(t, masterKey, dataKey, false, + yandexPassword{OriginURL: "https://a.yandex.ru", UsernameVal: "alice", Password: "hunter2"}, + yandexPassword{OriginURL: "https://b.yandex.ru", UsernameVal: "bob", Password: "hunter3"}, + ) + + var out testCollector + require.NoError(t, extractYandexPasswords(nil, path, &out)) + logins := collected[record.Login](t, &out) + require.Len(t, logins, 2) + for _, l := range logins { + assert.Empty(t, l.Password) + } + assert.Len(t, out.fails, 2, "each login without its password is a record-level problem") } func TestExtractYandexPasswords_WrongMasterKey(t *testing.T) { @@ -120,10 +142,13 @@ func TestExtractYandexPasswords_WrongMasterKey(t *testing.T) { }, ) - // A wrong master key fails at the intermediate step, surfacing as an error - // from the extractor. - err := extractYandexPasswords(masterkey.Set{masterkey.V10: wrongKey}, path, &testCollector{}) - require.Error(t, err) + // A wrong master key fails at the intermediate step, so the login exports without its password. + var out testCollector + require.NoError(t, extractYandexPasswords(masterkey.Set{masterkey.V10: wrongKey}, path, &out)) + logins := collected[record.Login](t, &out) + require.Len(t, logins, 1) + assert.Empty(t, logins[0].Password) + assert.Len(t, out.fails, 1) } func TestYandexLoginAAD_NoMasterPassword(t *testing.T) { diff --git a/rfcs/000-goals-and-constraints.md b/rfcs/000-goals-and-constraints.md index 35493dd..d6fd45d 100644 --- a/rfcs/000-goals-and-constraints.md +++ b/rfcs/000-goals-and-constraints.md @@ -43,7 +43,7 @@ The rewrite is invisible from the outside. Every item below behaves exactly as i | Archive | zip layout `/`, readable by v1.1.0 `restore` | | Exit status | `0` when the run completes (including partial results and "no browsers found"); `1` when it cannot start or finish | -Not part of the contract: log lines and the human-readable summary on stderr, and row order where today's order is unspecified or wrong. Output may change only for listed bug fixes where today's output is wrong — Firefox history order, Firefox bookmark fields, Safari bookmark IDs, Firefox logins from a profile whose key cannot be recovered, the `browser` value `restore` stamps, and CocCoc cookies on a Windows machine that also has Yandex ([RFC-008](008-output-and-export.md)); each is called out where it is fixed. +Not part of the contract: log lines and the human-readable summary on stderr, and row order where today's order is unspecified or wrong. Output may change only for listed bug fixes where today's output is wrong — Firefox history order, Firefox bookmark fields, Safari bookmark IDs, Firefox logins from a profile whose key cannot be recovered, Yandex logins and cards whose data key cannot be recovered, the `browser` value `restore` stamps, and CocCoc cookies on a Windows machine that also has Yandex ([RFC-008](008-output-and-export.md)); each is called out where it is fixed. ## Hard constraints diff --git a/rfcs/008-output-and-export.md b/rfcs/008-output-and-export.md index a035539..5fbb5a8 100644 --- a/rfcs/008-output-and-export.md +++ b/rfcs/008-output-and-export.md @@ -72,6 +72,7 @@ Extractors emit records one at a time ([RFC-003](003-core-types.md)), but sortin - **Firefox bookmarks** — `folder` holds the real folder name instead of `url`, and `type` and `id` are filled; today they are always `url`, empty, and `0`. - **Safari bookmark IDs** — unique across the whole bookmark tree; today each ID is the index among its siblings, so IDs repeat across folders. - **Firefox logins without a key** — when a profile's key cannot be recovered (no `key4.db`, or a primary password is set), its logins are exported with empty usernames and passwords and the extraction is `partial`; today the run panics as soon as one of those logins uses the legacy cipher. +- **Yandex logins and cards without a key** — when a profile's data key cannot be recovered (no master key, a wrong one, or a master password is set), its logins and cards are exported with empty passwords and card numbers and the extraction is `partial`, as every other store's are; today none of them is exported. - **`browser` in `restore` output** — the display name (`Chrome`), as `dump` writes it; today `restore` writes the vault key (`chrome`). - **CocCoc cookies beside Yandex** — on Windows, ABE looks for a browser's program in its own install locations before registry App Paths. CocCoc and Yandex both ship `browser.exe`, and App Paths names only one of them, so today CocCoc's key is requested from Yandex's program and its `v20` cookies export with empty values. diff --git a/rfcs/011-testing-and-quality.md b/rfcs/011-testing-and-quality.md index 0ef4045..141b154 100644 --- a/rfcs/011-testing-and-quality.md +++ b/rfcs/011-testing-and-quality.md @@ -41,6 +41,7 @@ Each bug designed out by this rewrite gets a test that would have caught it, so - **Firefox history order**: `visit_count` descending for every browser, Firefox included. - **Safari bookmark IDs**: unique across the whole tree, not repeated per folder. - **Firefox without a key**: a profile with no `key4.db` still exports its logins with empty secrets, the extraction is `partial`, and the run goes on; a missing key makes decryption fail instead of panicking. +- **Yandex without a key**: logins and cards still export with empty secrets, each a record-level problem, so `list --detail`, which reads no key, counts them as today does. - **Arc multi-dir**: two `arc` user data dirs yield IDs `arc` and `arc-2`, distinct snapshots, and distinct `keys.json` vaults, while overrides and the vaults' `browser` key still use `arc`. - **`--zip` data loss**: a failing zip write leaves every output file in place. - **Late flag validation**: `-f bogus` exits `1` with no discovery call and no password resolution (both injected as spies). diff --git a/rfcs/012-migration-roadmap.md b/rfcs/012-migration-roadmap.md index a9fa607..1d39cb0 100644 --- a/rfcs/012-migration-roadmap.md +++ b/rfcs/012-migration-roadmap.md @@ -61,6 +61,7 @@ Leaves first, bottom-up along the dependency arrows ([RFC-002](002-package-layou - `dump`, `dumpkeys`, `archive`, `restore`, and `list` run on the pipeline. - `archive` writes the snapshot `manifest.json` and `restore` reads it as its `Discovery` ([RFC-007](007-snapshot-and-acquisition.md)): writer and reader land together, so the round trip is tested end to end, and every earlier archive stays byte-identical to today's. - Validate-first ordering, `--keychain-pw-stdin` with the new precedence, the `-p` fixes, the safe `--zip` order, and the `restore` stamp fix ([RFC-009](009-cli-surface.md)). +- Yandex logins and cards export without their data key, like every other store, so `list --detail` counts them without a key ([RFC-008](008-output-and-export.md)). ### Phase 8 — Delete & document