Repository navigation
Protect all persisted account credentials from plaintext storage - #698
Conversation
Cyd serialized the X-to-Bluesky migration's OAuth state and session, which carry access and refresh tokens plus a private DPoP key, into the account's plaintext SQLite config table, and the SQL debug logger echoed those values into logs and error reports. Introduce one credential facility for the desktop: - src/credentials keeps per-account vaults encrypted through Electron's safeStorage, outside every account database, media directory, and archive, owner-only on disk. It refuses to persist anything when no OS facility is available rather than falling back to plaintext. - Detect the platform backend honestly: Keychain on macOS, OS-backed protection on Windows, libsecret or KWallet on Linux, with Chromium's basic_text and unrecognized stores treated as unprotected, logged at startup and disclosed in a dismissible in-app warning bar. - Move the migration's OAuth state and session into the vault, and refuse credential keys in the config table so they cannot come back. - Sweep legacy plaintext rows when an account database opens: migrate what can be protected, discard what cannot, then checkpoint the WAL and vacuum so the deleted bytes do not survive. - Redact SQL statement parameters to type and length in debug logs and in the errors that reach error reports. - Delete an account's whole credential namespace when the account is deleted, alongside the existing disconnect revocation. Document the threat model, platform behavior, and a manual verification checklist in docs/security/credential-storage.md. Fixes #671 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Standards axis: - Use the glossary's term throughout: "Cyd credential store", not "credential storage". Renames the error, the availability check, the renderer bar, and its i18n namespace. - Stop logging credential names, which can carry a Bluesky DID (ADR 0029), and stop logging the OAuth state and the callback query string that carries the authorization code. - Record the new decisions as ADR 0033 rather than only in docs/security. - Move the IPC definition to src/credentials/ipc.ts, matching how the account modules are laid out. - Name the credential keys once in src/credentials/keys.ts instead of three times across the store, the sweep, and the config guard. - Replace the (namespace, key) pair threaded through six functions with accountCredentials(accountID), so callers name a credential and nothing else. - Share one safeStorage test double through the electron fixture. - Validate the vault version on read, which also fixes a spread that defeated its own default. Spec axis: - Revoke before discarding: deleting an account now asks the authorization server to invalidate the Bluesky session first, and a failed revocation never blocks the deletion. - When the sweep discards credentials it could not protect, clear the stored DID too, so the account stops claiming a connection whose session is gone. - Refuse to persist to an unrecognized Linux password store. basic_text is the only sanctioned fallback; Cyd cannot vouch for a store it cannot name. - Give each disclosure its own words, and say that Chromium keeps persisting X login cookies either way, rather than implying Cyd stores nothing. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Manual review on Linux found the basic_text fallback unreachable. Electron's safeStorage.isEncryptionAvailable() returns false whenever Chromium falls back to the basic_text password store, unless the app calls setUsePlainTextEncryption(true), which Cyd does not. That is exactly the keyring-less case the fallback existed for, so getCredentialProtection() short-circuited to "unavailable" and never reached its basic_text branch. On a Linux desktop with no keyring the migration could not connect at all, and the legacy sweep destroyed a working session and cleared blueskyDID on first launch after upgrade. The unit tests could not catch it: the shared safeStorage double pinned isEncryptionAvailable to true while overriding only the backend name, describing a machine that cannot exist. Cyd now always persists, and discloses when it cannot protect: - Vault version 2 records "protected" per value. safeStorage ciphertext where the OS offers a keyring, the credential itself where it does not. Per value rather than per vault, so installing a keyring protects everything written afterwards without invalidating what is on disk. Version 1 vaults still read. Owner-only permissions are unchanged. - getCredentialProtection() decides only whether the OS protects, never whether to persist. It reads the Linux password store even when encryption is unavailable, so the warning bar can name it, and it treats a keyring-backed name with no working encryption as unprotected: a backend name is not a promise. - The legacy sweep always migrates. The rows still leave the config table, the WAL, and the free pages, which is the real improvement without a keyring, because the vault is owner-only and outside the archives, exports, and error reports the config table was not. It no longer discards credentials or clears the DID. - Drop CredentialStoreUnavailableError, isCredentialStoreAvailable, and CredentialProtection.canPersist. Nothing refuses any more, and a field that is always true invites a caller to branch on it. - The unrecognized and unavailable warnings said Cyd would not save the connection. Both now say the credentials are stored without operating-system protection and that anyone who can read the files can use them. Cyd stores plaintext itself rather than calling setUsePlainTextEncryption(true). Chromium's basic_text encrypts with a hard-coded key: the same exposure, but it would write base64 that looks encrypted and record protected: true. ADR 0033 is rewritten and renamed, and docs/security/credential-store.md follows, including the Electron coupling that made the original design look correct. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Manual verification harness (Linux done, macOS/Windows open)This exercises the real credential code against the real OS keyring, which the unit tests cannot do: the shared It uses a throwaway settings directory via Running itSave as # node_modules must resolve from the harness directory
ln -sfn "$PWD/node_modules" /tmp/cyd-manual/node_modules
./node_modules/.bin/esbuild /tmp/cyd-manual/harness.ts \
--bundle --platform=node --format=cjs --target=node20 \
--external:electron --external:better-sqlite3 --external:electron-log \
--outfile=/tmp/cyd-manual/harness.js
rm -rf /tmp/cyd-manual/profile && mkdir -p /tmp/cyd-manual/profile/settings
TEST_MODE=1 TEST_SETTINGS_PATH=/tmp/cyd-manual/profile/settings \
./node_modules/.bin/electron --no-sandbox \
--user-data-dir=/tmp/cyd-manual/profile /tmp/cyd-manual/harness.jsExit code is non-zero if any check fails. Add Linux results on 09895f8
In every mode the legacy canary is greppable in the db/WAL before the sweep and absent from For macOS and WindowsThe
|
openCydURL() logged the whole callback URL, and the callback handler logged url.search again, both at info level. That query string carries the OAuth authorization code, which is an account-control credential, and dev builds write info to disk, so the code landed in main.log verbatim. The "Invalid Cyd URL" dialog printed it on screen too, on exactly the path that fails today. Log and display the URL without its query string. The renderer half of this was already fixed; this is the main-process half, which the credential work missed because nothing greps the logs. Unreachable in practice until #699 is fixed, since the callback never arrives, but live the moment it is. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Manual testing on Linux found the warning bar below the fold. It was position: relative, so it sat in the document flow after TabsView and the user had to scroll the whole window to reach it. A security disclosure nobody sees is not a disclosure. Anchor both bottom bars in one .bottom-bars flex column, so they stack instead of overlapping however far their text wraps. The updates bar keeps its right-hand alignment but is laid out in flow inside the stack, rather than positioning itself absolutely, which means no pixel offset to get wrong when the disclosure wraps to another line. The container ignores pointer events so it does not swallow clicks in the empty space beside a bar. Shorten the three disclosures by about 40%. Each still says what is wrong, what the risk is, and how to fix it, and the bar still names the password store: No system keyring found, so Cyd stores your logins unencrypted. Anyone who can read your files can use them. Install GNOME Keyring (libsecret) or KWallet, then restart Cyd. Verified in the app on a real profile running with --password-store=basic: the bar is visible without scrolling, names basic_text, dismisses, and returns on the next launch. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Manual review on Windows found two claims in the threat model that do not hold there, both invisible to the unit tests. supportsOwnerOnlyPermissions() is false on win32, so the store never chmods and the vault inherits its directory's ACL. Measured with icacls: under the default %APPDATA% profile that inheritance is owner-only (the user, SYSTEM, Administrators), but a profile placed with --user-data-dir somewhere permissive, such as C:\temp, inherits BUILTIN\Users:(RX) and Authenticated Users:(M) and is readable and writable by every local account. On POSIX the explicit chmod clamps this back wherever the profile sits; on Windows nothing does. The threat model stated 0700/0600 without qualification. The Windows checklist also asked for the wrong experiment. safeStorage on Windows is not a separate OS vault: Chromium encrypts with its own random AES-256-GCM key, hands Cyd a v10 blob for the vault, and keeps that key in the profile's Local State wrapped with DPAPI. Both halves are files inside the profile, so DPAPI is the only barrier. Copying the vault alone to a second account fails merely because that profile minted a different AES key, which would happen even with DPAPI doing nothing. The check now copies Local State too. Restarts were never covered. Local State is written at shutdown, so a profile killed before its first clean quit loses the AES key and every entry in the vault; that is now a checklist item, alongside the Windows results this review confirmed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R8TQnZEgvPamkxnqNrHkRB
Windows manual verificationWindows 11 Pro 26200, Electron 41.7.1, branch at
Confirmed
Finding 1 — the
|
| Copied into the new profile | Result |
|---|---|
| vault only | does not decrypt — could not decrypt a credential for account 9001, discarding it, entry dropped |
vault + Local State |
decrypts fine, returns the original canary |
The checklist currently says "copy the vault to another Windows user account and confirm
Cyd there cannot decrypt it". That passes for the wrong reason: the receiving profile
minted a different AES key, which would happen even if DPAPI were doing nothing at all.
The test that actually exercises DPAPI must copy Local State too. Checklist corrected
in this branch.
Finding 3 — a credential written before the first clean quit is lost
Local State is written during shutdown. A profile killed before it ever quits cleanly
never persists the AES key, so the next launch mints a new one and every vault entry
becomes undecryptable and is dropped. Confirmed both ways: app.exit() left no Local State and lost the credential; a graceful quit wrote it and the credential survived the
restart.
Recoverable — the user reconnects — and the blast radius is only the first session. But
nothing in the tests or the checklist covered a restart at all, so it is now a checklist
item.
Still outstanding
Cross-user decryption— done, see the follow-up comment. Confirmed against a
second local account: both files readable, DPAPI refused the key. Checklist updated in
53f19a10.- Live OAuth connect / disconnect / delete, still blocked behind Bluesky OAuth callback never reaches the desktop app: redirect scheme and path do not match what Cyd registers #699. The credential
write path itself is exercised by the harness against realsafeStorage, but
revocation-at-the-server on disconnect remains unverified on every platform. - Warning bar absence in the running app. Asserted indirectly:
disclosureRequired
isfalseon this machine.
(This comment was written by an LLM.)
Confirmed against a second local account on the same machine. Both the vault and the profile's Local State were readable by that account, and DPAPI still refused the wrapped AES key with "Key not valid for use in specified state", so the v10 ciphertext is undecryptable there. This is the one place in the checklist where protection at rest is shown adversarially rather than inferred, and it now tests the right thing: a readable file and an unusable credential, which is the guarantee Windows actually offers, rather than a vault that failed to decrypt only because the receiving profile had minted a different key. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R8TQnZEgvPamkxnqNrHkRB
Cross-user decryption: confirmedThe last outstanding Windows item is now done, in the corrected form — vault and Both halves of the credential were readable by the second account — the staging The positive control matters here: run as the owning user, the same script unwraps the What this establishes: on Windows the vault's protection at rest is real, and it rests What it does not establish: nothing about an attacker who is already the user, or who Still outstanding on Windows, unchanged: the live connect / disconnect / delete walkthrough (This comment was written by an LLM.) |
Manual verification on Windows against a real Bluesky session. This is the first time revoke-before-discard has been exercised on any platform, and it holds: disconnecting revokes at the authorization server, and the refresh token is rejected with "Invalid refresh token" on the next attempt, so a copied session cannot be renewed. Two things the threat model did not say, both found while checking it. Revocation kills the grant, not the tokens already minted from it. An access token issued before the disconnect keeps working until it expires, an hour at most on Bluesky, because an authorization server cannot retract one it has already signed. A check that reuses the access token therefore shows a session that looks alive when the grant is already dead, which is how this was nearly misread; the check has to back-date the saved token set's expiry to force the refresh path. A failed revocation is not detectable locally. @atproto/oauth-client discards the outcome of the revocation request, so Cyd cannot log it, retry it, or tell the user. A disconnect looks identical whether the server honored it or never received it, which is worth stating in a document that otherwise presents revocation as unconditional. The connect item is checked off as well: the vault holds only the session entry once the callback completes, and the account database's config table holds blueskyDID and nothing else. Deleting an account stays unchecked, but is noted as reaching the same disconnect() rather than being a second implementation. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R8TQnZEgvPamkxnqNrHkRB
Disconnect does revoke server-side — with two caveats worth documentingRan the live connect/disconnect flow on Windows against a real Bluesky account, Connect
Worth noting the config-table guard is stronger than a grep can show. There is DisconnectVault file removed, and the session really is revoked: Caveat 1: revocation kills the grant, not tokens already mintedThis nearly produced a false finding. Immediately after disconnect, a saved The grant was dead the whole time. Back-dating the saved token set's expiry to Any future check of this must force the refresh path. Testing with the access Caveat 2: a failed revocation is invisible to Cyd
async revoke(token) {
try { await this.request('revocation', { token }); }
catch { /* Don't care */ }
}So The threat model states revocation unconditionally, so I documented the gap Still uncheckedDeleting an account. It is the same code path, not a second implementation: (This comment was written by an LLM.) |
The Keychain path had never been exercised. On macOS `osProtected` is inferred from the platform plus `isEncryptionAvailable()` alone, with no backend name to cross-check, so the checklist now asks for the Keychain item itself and for its creation time to match the startup log line. Note the two paths that differ on macOS and produce a false pass when taken from the Linux instructions: the log lives under `~/Library/Logs` rather than userData, and `--user-data-dir` does not redirect `dataPath`. Also record that revoking at a Bluesky-hosted entryway can take fifteen minutes to propagate, which is a second reason an access token outlives a disconnect and makes a hand-tested revocation look like it failed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
macOS (Keychain) passes — and the
|
Fixes #671.
Cyd serialized the X-to-Bluesky migration's OAuth state and session — access and refresh tokens plus a private DPoP key — into the account's plaintext SQLite
configtable, and the shared SQL debug logger echoed those values into logs and error reports. This adds one credential facility for the desktop and moves that material into it.What changed
src/credentials/— one store for account-control credentials.accountCredentials(accountID)returns a per-account vault encrypted through ElectronsafeStorage, written owner-only to<settings>/credentials/account-{id}.json, outside every account database, media directory, and Cyd archive. Callers name a credential and nothing else. When no facility can protect a value it throwsCredentialStoreUnavailableErrorrather than falling back to plaintext.Backend detection. Keychain on macOS, OS-backed protection on Windows, libsecret or KWallet on Linux.
basic_textis the single deliberate fallback, allowed only because a Linux desktop without a keyring is common, and only with disclosure. A password store Cyd does not recognize is refused, not guessed at. The selection is logged at startup and surfaced in a warning bar that names the backend.OAuth material out of SQLite. The migration's state and session now live in the vault.
setConfigthrows if a credential key is written to theconfigtable, so it cannot come back.Legacy sweep. Opening an account database migrates old plaintext rows into the vault, deletes them, then checkpoints the WAL and vacuums so the deleted bytes do not survive. When the credentials cannot be protected it destroys them and clears the stored DID, so the account stops claiming a connection whose session is gone.
Redaction. SQL statement parameters reach debug logs and error reports as
<string:42>/<buffer:1024>, never as values. The OAuth state and the callback query string that carries the authorization code are no longer logged.Revoke before discard. Disconnecting and deleting an account both ask the authorization server to invalidate the session first; a failed revocation never blocks a deletion the user asked for.
Docs.
docs/security/credential-store.mdcovers the threat model, the platform table, and a manual verification checklist for macOS Keychain, Windows, GNOME/libsecret, KDE/KWallet, thebasic_textfallback, an unrecognized store, and the upgrade path. ADR 0033 records the decisions;CONTEXT.mdgains the two terms.Testing
npm test: 1265 tests passing, no type errors.npm run lintclean. New coverage for protected storage, the vault format, migration including WAL remnants, redaction, deletion, unavailable and unrecognized backends, and the disclosed Linux fallback.Judgement calls worth a second opinion
(This was written by an LLM.)
🤖 Generated with Claude Code