# Electron safeStorage keychain prompt on every launch

> Electron safeStorage asked for the keychain after every update of our ad-hoc signed app, and hung it on a locked screen. So the key left the keychain.

Source: https://mosaicbrowser.com/blog/secrets-leave-keychain

## Why the app's secrets left the macOS keychain

Electron safeStorage asked for the keychain after every update of our ad-hoc signed app, and hung it on a locked screen. So the key left the keychain.

![A prompt after every update, and a hang behind it, beside a screenshot: mosaic general settings: theme and how profiles launch](https://mosaicbrowser.com/covers/secrets-leave-keychain.webp)

An Electron app that uses `safeStorage` on macOS shows a keychain prompt on every launch when its code signature keeps changing. Ours changed with every build, because Mosaic was ad-hoc signed at the time. So "Mosaic wants to use your confidential information" came back after every update, and on a locked screen the app hung before it had a window. On 25 October 2026 we took the app's own secrets out of the keychain.

## What safeStorage was holding

Mosaic seals its store, proxy credentials and per-profile cookie keys under one data key. That key itself has to be wrapped by something. The first answer was Electron's [`safeStorage`](https://www.electronjs.org/docs/latest/api/safe-storage), which on macOS keeps its key in the login keychain. It looked ideal. There was no password to type, and a copy of the data folder was useless on another Mac, because the other Mac's keychain did not have the key.

Saved logins and their two-factor secrets went through `safeStorage` the same way, one value at a time.

## Why safeStorage showed a keychain prompt on every launch

The keychain gives an item away silently only to the code identity it already trusts. With a stable signing certificate, that identity survives an update. Mosaic was ad-hoc signed, and an ad-hoc signature is a hash of the app's contents. Every rebuild and every update was therefore an identity the keychain had never seen, and it asked again.

This is the same mechanism behind the [Chromium keychain prompt](https://mosaicbrowser.com/blog/keychain-prompt) our browser launches had. There, two command-line flags kept the engine away from the keychain. The app itself had no such flag. It called the keychain on purpose.

Mosaic is a desktop app

Email yourself the link and open it on your computer.

[How it works: Local first](https://mosaicbrowser.com/features/local-first)

## The hang nobody could see

The prompt was annoying. The hang was worse, and we diagnosed it on a live machine with the screen locked. The production app had a GPU helper running, no renderer, and a DevTools port that accepted connections and answered nothing.

`safeStorage`'s decrypt call is synchronous, so the main thread was blocked inside it, waiting for an authorisation prompt. A locked screen cannot show the prompt, and a blocked main thread cannot draw anything. Mosaic sat there with no window until someone killed it.

A control that blocks startup is not transparent, however little it asks of you on a good day.

## The tempting fix we did not use

Deriving the key from the Mac's hardware id would have kept a copied folder useless elsewhere, with no prompt at all. We turned it down because of how it fails. Replace a logic board and the hardware id changes, the key changes with it, and every profile is silently unreadable. A security control whose failure mode is losing profiles does not get switched on.

## Where the key went

From 25 October the data key sat in `vault.json`, a file only your user can read, beside the data. Saved logins and 2FA secrets are now sealed under that same data key instead of `safeStorage`. A value written by an older build is unwrapped once and sealed again the next time that login is saved.

Two attacks we had measured stayed fixed: the store being readable by other users, and cookies sitting under Chromium's public mock-keychain password ([that measurement](https://mosaicbrowser.com/blog/mock-keychain-cookies) is the reason the vault exists). What the file mode gave up was the copied-folder property, and app lock in Settings › Security covered it for anyone who wanted it: a password, stretched with scrypt, that nothing decrypts without.

Since 2 November 2026 there is a stronger default. The data key is wrapped under your Mosaic account, from a secret the account server gives only to a signed-in session on a computer it has bound. A copied folder does not open for a different account, or with nobody signed in. App lock still adds a password on top. None of it touches the keychain.

## Getting old installs off it

Moving an existing install off the keychain needs one last keychain read, and it took four attempts to stop that read from causing the hang it was meant to remove.

1. Running it at startup, before the window, hung exactly as before.
2. Showing the window first and then reading still blocked the main thread a moment later. The window never came to the front and the prompt never appeared.
3. A Continue button made it a user action, and clicking it beachballed for the same reason: the call was still synchronous on the main thread.
4. Reading the key in a child process, through `/usr/bin/security`, kept the app responsive while the prompt waited.

Even that prompt did not surface reliably from inside the app. The shipping answer is that the app never reads the keychain to open its store. The one read left is a single saved login written by an older build, unwrapped once and resealed under the data key. An install from before the change is told so on its lock screen and is migrated once by a script run from Terminal, where the prompt does appear. It proves the recovered key opens the store before it writes anything.

If you ship an Electron app with `safeStorage`, the lesson that transfers is narrow: never make a synchronous keychain call on the main thread before a window is showing, and with an unstable signature expect the prompt after every update. What Mosaic keeps on your computer, and what never leaves it, is set out under [local-first](https://mosaicbrowser.com/features/local-first); how saved logins are filled is on [logins and 2FA](https://mosaicbrowser.com/features/logins-and-2fa).

## Sources

1. [Electron documentation: safeStorage](https://www.electronjs.org/docs/latest/api/safe-storage), read November 2, 2026

## Questions

### Why does Electron's safeStorage show a keychain prompt on every launch?

On macOS, safeStorage keeps its key in the login keychain, and the keychain releases it silently only to the code identity it already trusts. An ad-hoc signed app gets a new identity with every build, so each update asks again.

### Can safeStorage hang an Electron app?

Yes. The decrypt call is synchronous. If the keychain needs an answer, the main thread waits, and a blocked main thread cannot draw the window the prompt needs. We measured exactly that: helper processes running, no renderer, no window.

### Where does Mosaic keep its data key now?

Not in the keychain. Since 2 November 2026 it is wrapped under your Mosaic account, so the library opens only while you are signed in; app lock adds a password on top. The app no longer keeps any of its own secrets there.

### Why not derive the key from the Mac's hardware?

Because its failure is silent data loss. Replace a logic board and the key changes, and every profile becomes unreadable. A security control whose failure mode is losing profiles does not get switched on.

## Related

[Chromium's keychain prompt on a Mac, and where ours came from](https://mosaicbrowser.com/blog/keychain-prompt): Chromium reads its Chromium Safe Storage keychain item at startup. Our prompts never came from app launches: scripts started browsers without the flags.

[Chromium's mock keychain, and why we encrypt the store](https://mosaicbrowser.com/blog/mock-keychain-cookies): Chromium's --use-mock-keychain keeps cookie encryption on but uses a password from its own source. We read a live session cookie off disk, then sealed it.

[Local first: your profiles stay on your computer](https://mosaicbrowser.com/features/local-first): Mosaic has no cloud copy of your profiles. Profiles, cookies and proxies stay on your computer, encrypted on disk, with app lock, daily backups and a trash.

[2FA codes per browser profile, with a login vault each](https://mosaicbrowser.com/features/logins-and-2fa): Mosaic keeps 2FA codes per browser profile: each profile has its own login vault with TOTP codes, shown with a countdown and typed with real keystrokes.









[One Dock tile per window slot, and a banner we can't stop](https://mosaicbrowser.com/blog/dock-tile-per-slot): macOS gives one Dock tile per app identity, and greets each new one with a banner. We pool identities by open window: five, not one per profile.

[Mosaic gives every profile's cookies their own key](https://mosaicbrowser.com/blog/cookie-key-per-profile): Chrome on a Mac turns a Keychain password into an AES key with PBKDF2. Our engine lets Mosaic pass each profile its own password and keeps the v10 format.

## Mosaic, on your own computer

The browser this blog is about: its own Chromium, fingerprints from real machines and a proxy IP per profile. Free covers 3 profiles with no card, and Pro is $25 a month for any number of them.

Mosaic is a desktop app

Email yourself the link and open it on your computer.
