Skip to content

fix(browser): report app-bound encrypted cookies instead of a silent zero - #13193

Closed
manuaudio wants to merge 2 commits into
stablyai:mainfrom
manuaudio:fix/cookie-import-app-bound-encryption
Closed

manuaudio wants to merge 2 commits into
stablyai:mainfrom
manuaudio:fix/cookie-import-app-bound-encryption

Conversation

@manuaudio

@manuaudio manuaudio commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Closes #13192.

Summary

Importing cookies from Chrome/Edge 140+ on Windows now says why it failed instead of reporting a clean zero.

Before, the summary read importedCookies: 0 with totalCookies > 0 and no error — indistinguishable from an empty profile. Now the import surfaces a warning naming the cause and the workaround: export the cookies from the browser and use Import from File.

Root cause

decryptCookieValueRaw validates the version prefix as /^v\d\d$/ and then routes anything on Windows to the AES-256-GCM path:

const version = encryptedBuffer.subarray(0, 3).toString('utf-8')
if (!/^v\d\d$/.test(version)) return null
if (keyResult.mode === 'aes-256-gcm') return decryptAes256Gcm(encryptedBuffer.subarray(3), keyResult.key)

v20 satisfies that regex, so every app-bound row is fed to GCM with the user's DPAPI key, fails, and returns null. The caller then collapses it into the generic skip:

if (!raw) { skipped++; continue }

which is the same branch a malformed row takes. That is why the failure is invisible: the rows are read fine, they just decode to nothing, and nothing distinguishes "one bad row" from "this entire profile uses an encryption scheme we cannot read".

What changed

  • isAppBoundEncryptedCookie() — exported predicate for the v20 prefix.
  • The row scan counts app-bound rows before attempting decryption, since after decryptCookieValueRaw returns null they are indistinguishable from malformed ones.
  • When nothing imported and app-bound rows were present, the summary carries a new app-bound-encryption warning with the count.
  • Toast copy for the new warning code, with the catalog key generated via pnpm run sync:localization-catalog.

Decryption behaviour is unchanged. The v10/v11 paths on macOS and Linux are untouched, and no attempt is made to decrypt v20 — as the issue notes, that requires the browser's own elevation service (IElevator::DecryptData) and is not viable from Electron. An honest, actionable error is the useful outcome.

Credit to the reporter for the diagnosis; this implements the "at a minimum" suggestion from the issue rather than the fork patch, which I did not have access to.

Screenshots

A warning toast where there was previously a silent success. No layout or component change — it reuses the existing warning-toast mechanism and its discriminated union, so it renders exactly like the import warnings already in the flow.

I don't have a Windows machine with a Chrome 140 profile to capture it against, which is the same reason the end-to-end note below exists.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test — scoped to the touched tree, not the full suite (see below)
  • pnpm build
  • Added or updated high-quality tests that would catch regressions

pnpm typecheck and oxlint pass. All three localization verifiers (catalog, extraction, coverage) exit 0. 603 tests across src/main/browser/ pass, including the existing cookie-import suites. Scoped suites rather than a full pnpm build; no packaging or dependency surface is touched.

New browser-cookie-import-app-bound.test.ts covers the v20 prefix, the v10/v11 prefixes it must not touch, a plaintext value, and short/empty buffers.

Verified non-blind: stubbing the predicate to return false fails only the detection assertion while the four negative cases keep passing — so the test distinguishes the fix from its absence rather than merely exercising the function.

I could not reproduce on Windows from this machine, so the detection is verified at the byte level and by unit test rather than against a live Chrome 140 profile. Worth a maintainer with Windows confirming the toast end to end before this lands.

AI Review Report

Reviewed with Claude Opus 5 against the CONTRIBUTING checklist.

  • Cross-platform (macOS/Linux/Windows) — the predicate is byte-level and platform-independent, but only reachable in practice where v20 appears, which is Windows. macOS/Linux v10/v11 decryption is untouched and covered by the existing suites; the new negative cases pin that those prefixes are not caught by the predicate. No path handling, shell behaviour, accelerator or shortcut label involved.
  • SSH/remote/local — cookie import is a local-profile operation; no wire, IPC or remote surface changes.
  • Agent/integration/git provider — none touched.
  • Performance — one 3-byte prefix comparison per row, on a path that already decrypts every row.
  • UI quality — reuses the existing warning-toast mechanism; no new component, token or layout. Copy is localized through the normal catalog flow rather than hardcoded.

What it flagged and I acted on: the first cut inferred app-bound encryption from "imported 0 of N", which would also fire on a profile whose rows all failed for unrelated reasons. It now counts the v20 rows explicitly before decryption is attempted, so the warning names a cause it actually observed.

Security Audit

Reviewed for input handling, command execution, path handling, auth, secrets, dependency and IPC risk. This one touches cookie material, so it got the closest look.

  • No decryption weakened or bypassed. The change adds a predicate and a counter. No key handling, no new crypto path, no fallback that would decrypt something the old code refused. v10/v11 GCM and DPAPI paths are byte-for-byte unchanged.
  • No cookie values logged or surfaced. The predicate reads the first three bytes of the encrypted blob — the scheme tag, not plaintext. The diagnostic line and the toast carry a count only. No host, name, or value from any row reaches the log or the UI.
  • Input handling — inputs are rows from a local SQLite profile the user already pointed us at. Short and empty buffers are covered by tests so the prefix read cannot over-read.
  • Command execution / path handling — none added.
  • IPC — the summary already crossed the existing channel; this adds one warning code to a discriminated union that is already validated on the other side. No new surface.
  • Dependencies — none added.

Follow-up: none required for this change. The underlying inability to read v20 is a browser-imposed limit, not something to work around.

Notes

Windows-specific in practice — v20 app-bound encryption ships in Chrome/Edge 140+ on Windows only. The code path is platform-neutral but will not fire on macOS or Linux profiles.

The one open item is the end-to-end confirmation on a real Windows profile, flagged above. If someone on the team has one handy I'd appreciate the check; if it looks wrong I'll fix it.

X: @manuaudiomix

@manuaudio
manuaudio requested a review from brennanb2025 as a code owner August 8, 2026 13:04
@coderabbitai

coderabbitai Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a8498cb1-0664-4404-b497-32d4d9ff5b71

📥 Commits

Reviewing files that changed from the base of the PR and between 09ec516 and c3ea2c0.

📒 Files selected for processing (6)
  • src/main/browser/browser-cookie-import-app-bound-surface.test.ts
  • src/main/browser/browser-cookie-import-app-bound.test.ts
  • src/main/browser/browser-cookie-import.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/lib/browser-cookie-import-toast.ts
  • src/shared/types.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/shared/types.ts
  • src/main/browser/browser-cookie-import-app-bound.test.ts
  • src/renderer/src/lib/browser-cookie-import-toast.ts
  • src/main/browser/browser-cookie-import-app-bound-surface.test.ts
  • src/renderer/src/i18n/locales/en.json
  • src/main/browser/browser-cookie-import.ts

📝 Walkthrough

Walkthrough

The Chromium cookie importer detects v20 app-bound encrypted cookies and counts them separately. When no cookies are imported, the result includes an app-bound-encryption warning with the encrypted-cookie count. The shared warning type, renderer toast handling, and English localization support this warning. Tests cover detection, import warning counts, successful decryptable-cookie imports, plaintext rejection, and undersized buffers.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix: reporting app-bound encrypted cookies instead of silently returning zero imports.
Description check ✅ Passed The description clearly covers the change, cause, scope, testing, security, and linked issue, although some template headings and visual attachments are omitted.
Linked Issues check ✅ Passed The changes satisfy issue [#13192] by detecting v20 cookies, reporting an actionable warning, preserving v10/v11 behavior, and adding regression tests.
Out of Scope Changes check ✅ Passed The implementation, localization, toast handling, type updates, and tests are directly related to the linked issue and stated pull request objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/browser/browser-cookie-import.ts (1)

1807-1820: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

The app-bound-encryption warning never fires because of an earlier return.

imported and decryptedCookies.length stay in lock-step: every push to decryptedCookies (around line 1777) is immediately followed by imported++ (line 1803). This means whenever imported === 0, decryptedCookies.length is also 0.

The block at Lines 1807-1820 already returns early when decryptedCookies.length === 0, before the function reaches the new warning logic at Lines 1869-1875:

if (decryptedCookies.length === 0) {
  ...
  return { ok: true, profileId: '', summary: { ..., domains: [] } }
}

The new check if (imported === 0 && appBoundEncrypted > 0) at Line 1872 can only be true when decryptedCookies.length === 0, which means the function has already returned by then. This is exactly issue #13192's scenario: a browser where every cookie is v20 app-bound produces zero imports, so it hits the early return and never reaches the warning code. The app-bound-encryption warning this PR adds cannot ever be surfaced for the case it was built to fix.

Move the warning computation into the early-return branch, and drop the now-unreachable check further down.

🐛 Proposed fix: compute the warning before the early return
     if (decryptedCookies.length === 0) {
       closeStagingDb()
       discardStagingFile()
+      const earlyWarning: BrowserCookieImportSummary['warning'] =
+        appBoundEncrypted > 0
+          ? { code: 'app-bound-encryption', encryptedCookies: appBoundEncrypted }
+          : undefined
+      if (earlyWarning) {
+        diag(`  ${appBoundEncrypted} cookies use app-bound encryption (v20) and cannot be decrypted`)
+      }
       return {
         ok: true,
         profileId: '',
         summary: {
           totalCookies: sourceRows.length,
           importedCookies: 0,
           skippedCookies: skipped + integritySkipped,
-          domains: []
+          domains: [],
+          ...(earlyWarning ? { warning: earlyWarning } : {})
         }
       }
     }
     let warning: BrowserCookieImportSummary['warning']
-    // Why: without this the import reports a clean zero, which reads as "no cookies to import"
-    // rather than "this browser encrypts cookies in a way Orca cannot read" (`#13192`).
-    if (imported === 0 && appBoundEncrypted > 0) {
-      warning = { code: 'app-bound-encryption', encryptedCookies: appBoundEncrypted }
-      diag(`  ${appBoundEncrypted} cookies use app-bound encryption (v20) and cannot be decrypted`)
-    }
     if (memoryFailed > 0 && stagingAvailable) {

Also applies to: 1869-1875


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b1638627-95e7-4637-9e4d-f2878788b01c

📥 Commits

Reviewing files that changed from the base of the PR and between 54a9b58 and 093c369f72914f7ebca0a40058e3957b5da6093c.

📒 Files selected for processing (5)
  • src/main/browser/browser-cookie-import-app-bound.test.ts
  • src/main/browser/browser-cookie-import.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/lib/browser-cookie-import-toast.ts
  • src/shared/types.ts

@manuaudio

Copy link
Copy Markdown
Contributor Author

Correcting this PR — the original commit did not fix the reported case.

Acting on the observation that PRs here get closed for unverified mechanisms rather than style, I went back to prove the warning actually reaches the caller instead of only testing the predicate. It didn't.

decryptedCookies.length === 0 returns early, above the block where I attached the warning. A Chrome 140 profile where every cookie is app-bound decrypts nothing, takes that early return, and still reports a clean zero — exactly the scenario in #13192. My unit tests passed the whole time because they only exercised the prefix predicate.

Fixed in e0d8f8e88d, with an end-to-end test (browser-cookie-import-app-bound-surface.test.ts) that drives importCookiesFromBrowser against a real SQLite fixture of v20 rows with a working encryption key, and asserts summary.warning. That test fails against the previous commit — it is what surfaced the gap.

Also worth recording for review: with no key available the import already fails cleanly with "Could not access Google Chrome encryption key", so this path only matters when the key works and the rows are app-bound — i.e. Windows with Chrome/Edge 140+. 605 tests in src/main/browser/ pass.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/browser/browser-cookie-import.ts (1)

1729-1737: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Skip v20 rows before decryptCookieValueRaw.

Lines 1731-1733 detect app-bound encryption, but Line 1734 still attempts standard decryption. This conflicts with the stated v20 behavior. Increment skipped and continue after incrementing appBoundEncrypted.

Proposed fix
         if (isAppBoundEncryptedCookie(encBuf)) {
           appBoundEncrypted++
+          skipped++
+          continue
         }
         const raw = sourceKey ? decryptCookieValueRaw(encBuf, sourceKey) : null

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c75e99bc-a298-4af2-aa92-778b1ee36364

📥 Commits

Reviewing files that changed from the base of the PR and between 093c369f72914f7ebca0a40058e3957b5da6093c and e0d8f8e88da5a45327ac148925e45a85732356f0.

📒 Files selected for processing (2)
  • src/main/browser/browser-cookie-import-app-bound-surface.test.ts
  • src/main/browser/browser-cookie-import.ts

@AmethystLiang
AmethystLiang requested a review from OrcaWin August 9, 2026 16:52
@manuaudio
manuaudio force-pushed the fix/cookie-import-app-bound-encryption branch from e0d8f8e to bef02bd Compare August 12, 2026 00:01
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

manuaudio and others added 2 commits August 12, 2026 08:07
…zero

Chrome and Edge 140+ on Windows wrap every cookie in app-bound encryption
(v20 prefix), which only the browser's own elevation service can unwrap.
decryptCookieValueRaw accepts any /^v\d\d$/ prefix and hands v20 to the
AES-256-GCM path, where it fails and returns null. The caller counts that
as `skipped`, identical to a malformed row, so the import reports
importedCookies: 0 with no error — a failure that looks like an empty
profile.

Detect the v20 prefix while scanning rows and surface a warning naming the
cause and the workaround (export from the browser, then Import from File).
Decryption behaviour is unchanged; v10/v11 on macOS and Linux are untouched.

True v20 decryption is not viable outside the browser's elevation service,
so an honest error is the useful outcome here.

Closes stablyai#13192

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ZcrKK54K7sRnSkT6a6Jut
The warning was attached below a `decryptedCookies.length === 0` early
return, so it never fired for the case the issue actually reports: a
Chrome 140 profile where *every* cookie is app-bound decrypts nothing,
returns there, and still reported a clean zero.

Add an end-to-end test that drives importCookiesFromBrowser against a real
SQLite fixture of v20 rows with a working key. It failed against the
previous commit, which is how the gap surfaced.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ZcrKK54K7sRnSkT6a6Jut
@manuaudio
manuaudio force-pushed the fix/cookie-import-app-bound-encryption branch from bef02bd to c3ea2c0 Compare August 12, 2026 15:12
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@brennanb2025

Copy link
Copy Markdown
Contributor

Thanks for this — the diagnosis is right and the v20 detection is the correct call.

I've opened #14683, which supersedes this one. It keeps the core insight (detect the app-bound prefix and report it rather than swallowing it) and extends it in four ways:

  1. Covers every cause, not one prefix. The guard here is appBoundEncrypted > 0, so a zero-import from any other cause still reaches toast.success.
  2. Fixes the Linux path. getLinuxEncryptionKey derives the v11 key from an empty password when both secret-tool lookups fail, so it never returns null and the existing "Could not access encryption key" guard is unreachable on Linux (Browser cookie import from Chrome 150 fails to decrypt on Linux (XDG secret portal, no encrypted_key in Local State) #14181).
  3. One warning shape carrying a reason rather than a cause-specific code, so a future backend reports correctly without another union member.
  4. Adds a non-regression test proving v10 "peanuts" profiles still import when the keyring is unavailable — that is exactly when Chrome writes them, so failing hard there would break imports that work today.

Not a criticism of the work here; the general defect turned out to be the missing distinction between "decryption failed" and "no cookies present" rather than the v20 prefix specifically. Leaving this open for @OrcaWin to close as they see fit.

brennanb2025 added a commit that referenced this pull request Aug 15, 2026
Review-loop findings on the initial commit, all fixed here.

- CORRECTNESS: v11 rows were attempted with the v10 key when the keyring was
  unavailable. AES-128-CBC is unauthenticated, so a wrong key that yields valid
  PKCS#7 padding was accepted — roughly 1 in 256 per row. Garbage values were
  written into the jar as real cookies, and because those rows counted as
  successes the warning this PR adds could never fire. Key eligibility is now
  explicit per version rather than implicit in key ordering.

- CORRECTNESS: the CBC path returned an empty Buffer for a prefix-only value
  BEFORE checking eligibility. An empty Buffer is truthy, so an ineligible row
  counted as imported and reached the live-jar clear. Eligibility now precedes
  that branch and empty CBC ciphertext is rejected as malformed.

- ACCURACY: a named cause reported the TOTAL failure count, so one v20 row plus
  one corrupt row claimed both failed to app-bound encryption. Counts are now
  exact per cause, with the remainder reported separately and a tie falling back
  to 'unknown'. Exact-count approach carried over from #13193.

- The app-bound copy no longer dead-ends. It names the existing in-app file
  import without describing how to produce the file — Chrome has no native
  decrypted-cookie export, so concrete guidance would send users to an
  extension that can read their whole session jar.

- Direct prefix edge tests carried forward from #13193.

Repo-wide search found no second multi-key unauthenticated-CBC first-success
site, so this pattern was one occurrence rather than a class.

Co-authored-by: manuaudio <manuaudio@users.noreply.github.com>
brennanb2025 added a commit that referenced this pull request Aug 17, 2026
* fix(browser): report cookies an import could not decrypt

Supersedes #13193, which reported only the Windows v20 case.

Nothing distinguished "decryption failed" from "no cookies present". A row that
would not decrypt was folded into the generic `skipped` counter, and a profile
whose rows all failed returned ok:true with importedCookies:0 and no warning —
a green "Imported 0 cookies from Google Chrome." The two situations produce
opposite result shapes and the worse one reported success.

Attribute the cause at the point of failure, while the version prefix is still
in hand, and surface it as one `cookies-undecryptable` warning carrying the
reason. Covers all three known causes rather than one prefix:

- app-bound-encryption: Chrome/Edge 140+ on Windows write `v20`, which only the
  writing browser can unwrap. The version gate is a FORMAT check (`/^v\d\d$/`),
  so v20 passed it and failed inside AES like corruption.
- linux-keyring-unavailable: getLinuxEncryptionKey derived the v11 key from an
  empty password when both secret-tool lookups failed, so it never returned null
  and the "Could not access encryption key" guard was unreachable on Linux.
- unknown: any other cause still warns instead of reporting success.

Deliberately not a hard failure on Linux: Chrome falls back to the "peanuts" v10
key precisely when no keyring exists, so those profiles still import. Pinned by
a regression test.

Refs #13192, #14181

* fix(browser): attribute decrypt failures exactly and gate CBC by version

Review-loop findings on the initial commit, all fixed here.

- CORRECTNESS: v11 rows were attempted with the v10 key when the keyring was
  unavailable. AES-128-CBC is unauthenticated, so a wrong key that yields valid
  PKCS#7 padding was accepted — roughly 1 in 256 per row. Garbage values were
  written into the jar as real cookies, and because those rows counted as
  successes the warning this PR adds could never fire. Key eligibility is now
  explicit per version rather than implicit in key ordering.

- CORRECTNESS: the CBC path returned an empty Buffer for a prefix-only value
  BEFORE checking eligibility. An empty Buffer is truthy, so an ineligible row
  counted as imported and reached the live-jar clear. Eligibility now precedes
  that branch and empty CBC ciphertext is rejected as malformed.

- ACCURACY: a named cause reported the TOTAL failure count, so one v20 row plus
  one corrupt row claimed both failed to app-bound encryption. Counts are now
  exact per cause, with the remainder reported separately and a tie falling back
  to 'unknown'. Exact-count approach carried over from #13193.

- The app-bound copy no longer dead-ends. It names the existing in-app file
  import without describing how to produce the file — Chrome has no native
  decrypted-cookie export, so concrete guidance would send users to an
  extension that can read their whole session jar.

- Direct prefix edge tests carried forward from #13193.

Repo-wide search found no second multi-key unauthenticated-CBC first-success
site, so this pattern was one occurrence rather than a class.

Co-authored-by: manuaudio <manuaudio@users.noreply.github.com>

* fix(pr): preserve split worktree slice

Remove the unrelated rollback of the worktree-slice split and its forbidden max-lines baseline addition from this cookie-import PR.

* fix(browser): match the unknown decrypt reason explicitly

CI's type-aware code-quality gate flagged the reason switch as non-exhaustive:
the 'unknown' member was handled by `default:` rather than matched.

Matching it explicitly keeps the behaviour identical today and makes the gate
enforce the thing that matters — adding a new reason to the union now fails the
switch instead of falling silently into a generic message that would not
describe it.

This gate is separate from `oxlint` and is not covered by running oxlint on the
changed files, which is why it only surfaced in CI.

---------

Co-authored-by: manuaudio <manuaudio@users.noreply.github.com>
AmethystLiang pushed a commit that referenced this pull request Aug 17, 2026
* fix(browser): report cookies an import could not decrypt

Supersedes #13193, which reported only the Windows v20 case.

Nothing distinguished "decryption failed" from "no cookies present". A row that
would not decrypt was folded into the generic `skipped` counter, and a profile
whose rows all failed returned ok:true with importedCookies:0 and no warning —
a green "Imported 0 cookies from Google Chrome." The two situations produce
opposite result shapes and the worse one reported success.

Attribute the cause at the point of failure, while the version prefix is still
in hand, and surface it as one `cookies-undecryptable` warning carrying the
reason. Covers all three known causes rather than one prefix:

- app-bound-encryption: Chrome/Edge 140+ on Windows write `v20`, which only the
  writing browser can unwrap. The version gate is a FORMAT check (`/^v\d\d$/`),
  so v20 passed it and failed inside AES like corruption.
- linux-keyring-unavailable: getLinuxEncryptionKey derived the v11 key from an
  empty password when both secret-tool lookups failed, so it never returned null
  and the "Could not access encryption key" guard was unreachable on Linux.
- unknown: any other cause still warns instead of reporting success.

Deliberately not a hard failure on Linux: Chrome falls back to the "peanuts" v10
key precisely when no keyring exists, so those profiles still import. Pinned by
a regression test.

Refs #13192, #14181

* fix(browser): attribute decrypt failures exactly and gate CBC by version

Review-loop findings on the initial commit, all fixed here.

- CORRECTNESS: v11 rows were attempted with the v10 key when the keyring was
  unavailable. AES-128-CBC is unauthenticated, so a wrong key that yields valid
  PKCS#7 padding was accepted — roughly 1 in 256 per row. Garbage values were
  written into the jar as real cookies, and because those rows counted as
  successes the warning this PR adds could never fire. Key eligibility is now
  explicit per version rather than implicit in key ordering.

- CORRECTNESS: the CBC path returned an empty Buffer for a prefix-only value
  BEFORE checking eligibility. An empty Buffer is truthy, so an ineligible row
  counted as imported and reached the live-jar clear. Eligibility now precedes
  that branch and empty CBC ciphertext is rejected as malformed.

- ACCURACY: a named cause reported the TOTAL failure count, so one v20 row plus
  one corrupt row claimed both failed to app-bound encryption. Counts are now
  exact per cause, with the remainder reported separately and a tie falling back
  to 'unknown'. Exact-count approach carried over from #13193.

- The app-bound copy no longer dead-ends. It names the existing in-app file
  import without describing how to produce the file — Chrome has no native
  decrypted-cookie export, so concrete guidance would send users to an
  extension that can read their whole session jar.

- Direct prefix edge tests carried forward from #13193.

Repo-wide search found no second multi-key unauthenticated-CBC first-success
site, so this pattern was one occurrence rather than a class.

Co-authored-by: manuaudio <manuaudio@users.noreply.github.com>

* fix(pr): preserve split worktree slice

Remove the unrelated rollback of the worktree-slice split and its forbidden max-lines baseline addition from this cookie-import PR.

* fix(browser): match the unknown decrypt reason explicitly

CI's type-aware code-quality gate flagged the reason switch as non-exhaustive:
the 'unknown' member was handled by `default:` rather than matched.

Matching it explicitly keeps the behaviour identical today and makes the gate
enforce the thing that matters — adding a new reason to the union now fails the
switch instead of falling silently into a generic message that would not
describe it.

This gate is separate from `oxlint` and is not covered by running oxlint on the
changed files, which is why it only surfaced in CI.

---------

Co-authored-by: manuaudio <manuaudio@users.noreply.github.com>
@nwparker nwparker removed the P1 label Aug 19, 2026
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
)

* fix(browser): report cookies an import could not decrypt

Supersedes stablyai#13193, which reported only the Windows v20 case.

Nothing distinguished "decryption failed" from "no cookies present". A row that
would not decrypt was folded into the generic `skipped` counter, and a profile
whose rows all failed returned ok:true with importedCookies:0 and no warning —
a green "Imported 0 cookies from Google Chrome." The two situations produce
opposite result shapes and the worse one reported success.

Attribute the cause at the point of failure, while the version prefix is still
in hand, and surface it as one `cookies-undecryptable` warning carrying the
reason. Covers all three known causes rather than one prefix:

- app-bound-encryption: Chrome/Edge 140+ on Windows write `v20`, which only the
  writing browser can unwrap. The version gate is a FORMAT check (`/^v\d\d$/`),
  so v20 passed it and failed inside AES like corruption.
- linux-keyring-unavailable: getLinuxEncryptionKey derived the v11 key from an
  empty password when both secret-tool lookups failed, so it never returned null
  and the "Could not access encryption key" guard was unreachable on Linux.
- unknown: any other cause still warns instead of reporting success.

Deliberately not a hard failure on Linux: Chrome falls back to the "peanuts" v10
key precisely when no keyring exists, so those profiles still import. Pinned by
a regression test.

Refs stablyai#13192, stablyai#14181

* fix(browser): attribute decrypt failures exactly and gate CBC by version

Review-loop findings on the initial commit, all fixed here.

- CORRECTNESS: v11 rows were attempted with the v10 key when the keyring was
  unavailable. AES-128-CBC is unauthenticated, so a wrong key that yields valid
  PKCS#7 padding was accepted — roughly 1 in 256 per row. Garbage values were
  written into the jar as real cookies, and because those rows counted as
  successes the warning this PR adds could never fire. Key eligibility is now
  explicit per version rather than implicit in key ordering.

- CORRECTNESS: the CBC path returned an empty Buffer for a prefix-only value
  BEFORE checking eligibility. An empty Buffer is truthy, so an ineligible row
  counted as imported and reached the live-jar clear. Eligibility now precedes
  that branch and empty CBC ciphertext is rejected as malformed.

- ACCURACY: a named cause reported the TOTAL failure count, so one v20 row plus
  one corrupt row claimed both failed to app-bound encryption. Counts are now
  exact per cause, with the remainder reported separately and a tie falling back
  to 'unknown'. Exact-count approach carried over from stablyai#13193.

- The app-bound copy no longer dead-ends. It names the existing in-app file
  import without describing how to produce the file — Chrome has no native
  decrypted-cookie export, so concrete guidance would send users to an
  extension that can read their whole session jar.

- Direct prefix edge tests carried forward from stablyai#13193.

Repo-wide search found no second multi-key unauthenticated-CBC first-success
site, so this pattern was one occurrence rather than a class.

Co-authored-by: manuaudio <manuaudio@users.noreply.github.com>

* fix(pr): preserve split worktree slice

Remove the unrelated rollback of the worktree-slice split and its forbidden max-lines baseline addition from this cookie-import PR.

* fix(browser): match the unknown decrypt reason explicitly

CI's type-aware code-quality gate flagged the reason switch as non-exhaustive:
the 'unknown' member was handled by `default:` rather than matched.

Matching it explicitly keeps the behaviour identical today and makes the gate
enforce the thing that matters — adding a new reason to the union now fails the
switch instead of falling silently into a generic message that would not
describe it.

This gate is separate from `oxlint` and is not covered by running oxlint on the
changed files, which is why it only surfaced in CI.

---------

Co-authored-by: manuaudio <manuaudio@users.noreply.github.com>
@nwparker

Copy link
Copy Markdown
Contributor

Closing as fully superseded by merged #14683. That change carries this PR's v20 detection and user-visible app-bound-encryption warning through the complete import path, including the all-undecryptable early return, and gives the same From File guidance. It generalizes the warning to other causes and preserves successful v10 imports.

I checked the complete scope and follow-up comments here, verified the current import/toast implementation, and reran the focused regression tests. No separate decryption implementation is being dropped: this PR deliberately leaves decryption unchanged. Thanks for identifying both the format issue and the original early-return gap.

@nwparker nwparker closed this Oct 18, 2026
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.

[Bug] Browser cookie import silently imports 0 cookies on Chrome/Edge 140+ on Windows (v20 app-bound encryption)

5 participants