[Bug]: Desktop overwrites an undecryptable connection-catalog.json with an empty catalog, permanently deleting saved environments #23470
Before submitting#
- I searched existing issues. Related: #22216 (Mac Nightly 20261020 identity change, closed), #20906 (Alpha to Beta rename, closed), #8341 (orphaned safeStorage key, Windows), #4750 (non-atomic writes, corrupt document bricks the app). None covers the overwrite described here.
Area#
apps/desktop
Steps to reproduce#
- macOS, T3 Code Nightly with several saved environments (SSH targets and remote profiles).
- Have
connection-catalog.jsonencrypted under a safe-storage identity that differs from the one the running build uses. This happened naturally across nightlies: 20261020 usedT3 Code (Nightly) Safe Storage, and 20261021 (the #22216 fix) returned tot3code Safe Storage. Any user who re-saved the catalog on 20261020 now holds a file under the Nightly key. - Update to the next build and open the desktop.
Expected behavior#
If the catalog cannot be decrypted, the desktop leaves the file untouched. It tries other known identities (t3code, T3 Code (Nightly), T3 Code (Alpha), T3 Code (Beta)) and then re-encrypts the file under the current identity. If no identity works, it shows a recoverable error.
Actual behavior#
desktop.connectionCatalogStore.get fails with DesktopConnectionCatalogStoreProtectionError (decrypt-catalog). The renderer continues with an empty catalog, and its next desktop:set-connection-catalog call writes {"targets":[],"profiles":[],"credentials":[],...} over the file. The original catalog, including credentials and DPoP tokens, is gone. Remote environments and their threads disappear from the desktop, while the web client still shows them.
In 20261021 the store's get has no previous-identity fallback (the decryptWithPreviousName path seen in 20261020 traces is gone), and set writes unconditionally.
Suggested fix#
- Never let
setreplace a catalog that the lastgetfailed to decrypt. Keep the unreadable file (or move it toconnection-catalog.json.undecryptable-<ts>) until the user resolves it. - Restore a fallback in
getthat tries every historical safe-storage identity and migrates on success. - Write a
.bakof the previous document before each write (also helps #4750).
Impact#
Silent, permanent loss of all saved connections and their credentials after a routine update.
Version or commit#
0.1.2-nightly.20261021.3499, macOS arm64.
Logs or stack traces#
desktop.connectionCatalogStore.get Failure DesktopConnectionCatalogStoreProtectionError: decrypt-catalog
desktop.ipc.connectionCatalog.set Success (catalog shrinks from ~9 KB to 212 bytes)tanstack-source added labelsbug
This is the same problem as #34944, so I'm closing it in favour of that one. If it is different, say how and it will be reopened.
juliusmarminge closed this
Sign in to join this conversation.
Correction to the failure path above, after reading the source: on the Mac where the catalog was wiped,
desktop.connectionCatalogStore.getsucceeded at startup andsetfollowed 36 ms later. The empty write comes from the renderer's corrupt-catalog recovery inmakeCatalogStore(apps/web/src/connection/storage.ts), which writesEMPTY_CONNECTION_CATALOG_DOCUMENTwhen the returned catalog does not decode. The desktop backend has noquarantine, so nothing is kept. On the second Mac,getfailed withdecrypt-catalogand nothing was written.Proposed fix: #23488 keeps the existing file as
connection-catalog.json.unreadable-<ms>before the first write, if it does not decrypt and decode.