0173: The person imports Chrome sign-ins into the built-in browser, one chosen site at a time¶
- Implementation partial
Context and Problem Statement¶
The built-in browser of the desktop app keeps its own website partition (persist:hz-browser, ADR 0140), so a
person starts signed out everywhere and signs in again site by site. The owner asked for an import of Chrome's
cookies in 0.9.59. Cookies are sign-ins: whoever holds them is the person on that site. Chrome encrypts them with a
key in the person's Keychain.
Agents use the built-in browser (ADR 0162), so whatever lands in it is used by Heinzels and outside agents too. Who may start an import, what does the person agree to, how is the key read, and where may a value go?
Decision Drivers¶
- Only the person starts an import or an undo; no agent, Heinzel, token, paired device or the daemon can.
- The person decides in a place no local process can answer: the desktop app's own native dialog, per import and per removal, bound to the sites it shows. A terminal's y/N and the web session token can both be scripted.
- The person agrees per site, after seeing every site, is told that agents can then act as them there, and sees the key being read in macOS's own dialog.
- A value goes from Chrome's file into the built-in browser's own store and nowhere else: never a log, an answer, chat, MCP, a plugin, telemetry or a file of hz.
- The key is asked for every import and kept by nobody.
- Every imported site can be taken out again on its own.
- No new dependency. (The Public Suffix List ships as a data file,
public_suffix_list.dat, MPL 2.0.)
Considered Options¶
- hz reads and decrypts, the desktop writes; person-only operations on the CLI and web heads (chosen)
- Everything in the desktop's main process (the first proposal, PR #928): values never enter hz, but the
terminal could not start it, the key came from the
securitytool rather than the Keychain API, and the native Swift app needed a second copy of the crypto. - Chrome's own export: Chrome exports passwords, bookmarks and history, not site sessions; there is no supported cookie export.
- Sign in again per site (status quo): safest, and what the owner wants to save the person.
- An agent tool to import: refused: a session is the person's to hand over, never an agent's to take.
Decision Outcome¶
Chosen option: hz reads and decrypts, the desktop writes, person-only operations, because it gives the person both the Settings action and the terminal, reads the key through the system's Keychain API with macOS's own prompt, and keeps values between Chrome's file and the browser's store.
Who may.
hz ui browser cookie (profiles, preview, import, imported, remove) is on the cli and web heads only,
never MCP, so no agent sees it as a tool and no chat tool policy offers it. Every call checks, in the service, that
the head named the person as caller (Caller.kind == "person") and that the authentication is cli or
web-session; a Heinzel's turn, mcp-stdio, a token (api-bearer, even the owner's), a paired device or the widget
(web-device), the daemon and a call with no caller (a plugin's own call path) are refused before Chrome's
files are touched. The writes are agents="never".
What this check can and cannot do: it says who started the call. Code running inside a call the person started (an
operation of an installed plugin that the person runs from the terminal or the web app) resolves the same service
under the same caller, and no in-process check can tell it apart. A script that gives the CLI a pseudo-terminal and
types y, and any process holding the web session token, pass it as well. So this check is not what decides.
Who decides: the desktop app's native dialog and its one-time grant.
Every import and every removal asks the desktop app first (cookies_consent with the purpose, the profile and each
site with its count). One question names at most 25 sites, and the dialog lists every one of them, sensitive sites
first; a longer choice is asked in parts, one dialog and one grant each.
The sender's word decides nothing: the hz end
(forward) refuses a question with more than 25 sites, a site named twice, or a name that is no registrable domain
(a host such as www.mybank.de, or a public suffix such as com or co.ke), and sets each site's kind from its
own list before the desktop sees it; the desktop refuses more than 25 sites, top-level domains and generic second
levels (co.uk, gov.gh) on its own and sorts sensitive sites first itself. After a Cancel or an unanswered dialog
the desktop takes no new question for 10 seconds, so no process can keep the dialog in front.
The desktop's main
process shows a native message box (Electron dialog), in front, with the sites (sensitive kinds named), the
sentence "Heinzels and other agents that use the built-in browser can then
act as you on these sites.", what "Always Allow" in macOS's prompt means, and a warning to allow it only if the person started this
import themselves. Cancel is the default; the dialog closes unanswered after 100 seconds. Only the person's click on
Import (or Remove) makes a grant: 32 random bytes, for that purpose and those sites, the only live grant (a new
question ends the old one), ended by cookies_end after the hand-over or after five minutes. The Keychain is asked
only after that click.
Each cookies_set and cookies_remove carries the grant. Both the process holding the bridge (forward, which is
also the relay socket's end) and the desktop refuse a hand-over without the live grant, with a grant of the other
purpose, or with any cookie whose URL host or domain is outside the granted sites (host == site or below it). So a
local process that reaches the relay socket can neither plant a cookie nor sign the person out; at most it can make
the desktop ask, which the person sees and declines. The terminal's y/N question and the web dialog stay as
courtesy steps before it. Not covered: a process that can click the person's screen (Accessibility access) could
also click this dialog.
What the person agrees to.
- The dry run (
preview, the dialog's list) reads only hosts and attributes from a private copy of the profile'sCookiesdatabase and lists registrable domains with their counts; expired and partitioned cookies are counted as skipped. No Keychain access. - Nothing starts ticked. Email, bank or payments and sign-in providers carry a badge and stay out of "Select all
without a badge"; the person ticks them one by one. Known names count on every ending (
google.de,amazon.co.uk,ing.de), plus money words in the name (bank, pay, broker, ...). - Import names the ticked sites. Sites not in the profile or not named as the dry run names them are refused before the Keychain is asked. Without a connected desktop app it is refused before the Keychain too.
- The web dialog, the terminal's question and the desktop's native dialog all say that Heinzels and other agents that use the built-in browser can then act as the person on these sites; the terminal marks sensitive kinds.
- The desktop's native dialog decides (above).
- macOS asks whether the program may read "Chrome Safe Storage"; Deny ends the import with nothing read. Every consent tells the person to choose "Allow", not "Always Allow".
Reading and decrypting (macOS).
SecItemCopyMatching (Security framework, through ctypes) asks for the generic password Chrome Safe Storage,
account Chrome. hz is not on the item's access list, so macOS shows its prompt. The password is a bytearray;
the key is PBKDF2-HMAC-SHA1 (saltysalt, 1003 rounds, 16 bytes); values (v10/v11) are AES-128-CBC with an IV of
16 spaces, decrypted by CommonCrypto's CCCrypt. From database version 24 a plain text starts with SHA-256 of the
cookie's host, which must match its row, so a value moved to another host does not decrypt. Password and key are
overwritten after the read; copies Python made inside hashlib cannot be wiped and are dropped. Nothing caches the
key: every import asks macOS again.
Other systems.
They refuse, saying why: on Windows Chrome 127 and later binds its key to Chrome itself (app-bound encryption):
there is no supported route for another app. On Linux the key is in the desktop keyring (Secret Service,
Chrome Safe Storage); that route exists but is not built or tested, so it refuses. Every other system refuses.
Where values go.
Decrypted cookies exist in the hz process from decryption to the hand-over and are not returned, logged or kept.
The process that holds the desktop's bridge (the web server, ADR 0162) sends them as cookies_set frames to the
desktop app with the agent {id: "person:cookie-import", kind: "person"}; a terminal's import passes the same
frames through the owner-only relay socket (ADR 0117, 0162), whose end checks their shape and the grant and forwards
them.
The desktop takes cookie commands for that agent only, and no tab command for it. It checks each cookie (exact keys,
an http(s) URL, secure matching the scheme, a domain covering the URL's host) and sets it with
session.fromPartition("persist:hz-browser").cookies.set, never the product's session. Attributes are Chrome's:
host-only stays host-only, a domain cookie keeps its leading dot, path, Secure, HttpOnly, SameSite (-1
unspecified, 0 none, 1 lax, 2 strict) and expiry; a session cookie stays one. Partitioned and expired cookies
are skipped. The desktop answers counts and the indexes it refused, never a value.
The ledger ui/browser-cookies.json (state folder, mode 0600, read without following links) keeps per site the
Chrome profile, the time and each cookie's URL, name, domain and path, never a value; it is what remove undoes.
It is written after every batch the desktop took (a batch is at most 40 KiB), so a hand-over that fails half way
(the desktop timed out or quit) still leaves an undo for every cookie that came in.
The audit lines browser.cookie.import and browser.cookie.remove hold who (cli/web-session), the profile
and counts. Results hold sites and counts. No telemetry event exists for any of this.
Undo.
remove with sites, or --every, asks the desktop's dialog, then sends cookies_remove for the ledger's entries of
those sites under that grant and drops them from the ledger; Settings has a Remove per imported site. A cookie the
site set again under the same name and path after the import is removed too; cookies the site set later under other
names stay, so Settings says the imported cookies were removed, not that the person is signed out. Clear browsing
data (ADR 0140) still removes everything.
Consequences¶
- Good, because the person signs in to chosen sites once, from Settings or the terminal, and can take each back.
- Good, because no agent path reaches the import, every import and removal is decided in a native dialog no local process can answer, and macOS shows the key being read.
- Bad, because the values pass through the hz process and, from a terminal, the relay socket; both are the person's own processes, trusted as ADR 0117 trusts them.
- Bad, because agents then use those sessions in their own tabs (ADR 0162): Heinzels and outside agents can act as the person on every imported site. Every consent says so in one plain sentence, and sensitive sites are never pre-selected.
- Bad, because "Always Allow" in macOS's prompt is a grant to the program that asked, which is the Python interpreter hz runs in, not hz alone: after it, any script that interpreter runs, and any plugin in the hz process, can read Chrome's key without a prompt and decrypt all of Chrome's cookies outside hz altogether. The desktop's dialog still guards every import into the built-in browser, but not that. Every consent therefore says to choose "Allow". A later step can read the key from a signed component of the desktop app so that a grant never covers a general interpreter. Which program the prompt names is to be checked once on the owner's Mac.
- Neutral, because sites are registrable domains by the Public Suffix List (ICANN and private sections, wildcards and
exceptions), shipped as a data file and refreshed with hz releases; one tick never covers two owners below a
generic second level such as
co.keorgov.gh. - Neutral, because the native Swift app's browser keeps no cookies (
.nonPersistent()) and has no bridge: an import there says it needs the desktop app.
Confirmation¶
tests/unit/modules/ui_browser_cookie_test.py: a synthetic Chrome folder and a made-up password; decryption (v10, v11, version 23 and 24, host binding, wrong key), the macOS cipher on macOS, sites and categories, profile path checks, the dry run without the Keychain, attribute mapping, refusals for every non-person caller and on other systems, no exposure on MCP or chat tools, no value in any log, result or the ledger, the per-site undo, the terminal's hand-over through the relay, the relay end's shape check, a forged hand-over over the real relay socket refused without a grant, a grant bound to its sites, purpose and one hand-over and its time, a no in the desktop's dialog (also after a scripted terminal yes) importing and removing nothing before the Keychain, the CLI head with a pipedy, the ledger after a hand-over that fails half way, key and password wiped, the consent copy, sites under generic second levels, sensitive names on every ending, and the Keychain's not-found refusal with a made-up item.desktop/test/cookie-import.test.js: the desktop's checks, forged and out-of-site hand-overs refused, the one-time grant, the native dialog's text and buttons and its timeout, the website-partition store and its wiring in the main process, and the separation of person and agent commands.web/src/layout/ChromeCookies.test.tsxand the mounted journeytests/e2e/chrome_cookie_import_test.py(web/e2e/chrome-cookies.mjs): Settings > Browser through dry run, ticks, Import and Remove against the web head, with the desktop's own bridge client.- Not verified: a real Chrome profile and the real Keychain prompt (never read on the build machine: which program
it names and what "Always Allow" binds to), the native dialog in the packaged desktop app, and Electron's real
cookies.set. One manual import on the owner's Mac, then a site's undo, confirms them. An independent security review is required before release.
More Information¶
- Owner: the Chrome cookie import ships in 0.9.59, built on this design: user-initiated only, per-site consent after a dry run, the Keychain through the system API, other systems refuse, values only into the built-in browser's store, per-site undo.
- Chrome's documented export: https://support.google.com/chrome/answer/10248834