[Bug]: Desktop writes clerk-tokens.json without restrictive file mode (and allows unencrypted fallback) #15143
Before submitting#
- I searched existing issues and did not find a duplicate.
- I included enough detail to reproduce or investigate the problem.
Area#
apps/desktop
Steps to reproduce#
- Sign in to T3 Connect in the macOS desktop app.
- Check the token store:
ls -l ~/.t3/userdata/clerk-tokens.json.
Expected behavior#
The token store is created with mode 0600, like other credential files under ~/.t3/userdata (for example the files in userdata/secrets).
Actual behavior#
The file had mode 0666 (any local user could read and replace it). It was last written on 2026-08-07.
Cause, from the bundled code: the desktop app stores Clerk tokens with @clerk/electron storage({ path: stateDir, ... }), which uses electron-store. electron-store (conf) writes with configFileMode 0o666, reduced only by the process umask, and storage() does not forward a file mode. So the final mode depends on the umask of the launching process.
On this machine the __clerk_client_jwt value has the enc: prefix (Keychain encryption), so the read risk was limited. But the app also passes unencryptedFallback: true. Where OS encryption is unavailable (for example Linux without libsecret/kwallet), the token is stored as raw:<jwt> in this same file.
Impact#
- Any local user can delete or replace the token store, which signs the user out or injects state.
- Where
safeStorageis unavailable, the session token is stored in plain text in a file whose mode depends on umask.
Suggested fix: create the file with 0600 (for example chmod after the store is created, or pass configFileMode: 0o600 if the storage adapter allows it). Consider also removing unencryptedFallback, or at least enforcing 0600 when it is used.
Version or commit#
T3 Code (Nightly) desktop 0.0.46-nightly.20261003.2623
Environment#
macOS (Apple Silicon), desktop app.
Logs or stack traces#
N/A. Static finding from file mode and the bundled code in app.asar.
Reported with Claude Code (Claude Opus 5.5) during a local security audit.
juliusmarminge added labelsbug
juliusmarminge added labelssecurity
juliusmarminge added labelsvia-triage
Windows data point, plus one correction on the fallback half. Still reproduces at
0.1.1-nightly.20261016.3203(t3codeCommitHash: e3b35d1b2440), i.e. after this issue was filed.Root cause is unchanged, and it is upstream of the app. The shipped
app.asarbundle still contains theconf/electron-storedefaultconfigFileMode: 438(=0o666), and the@clerk/electronstorage adapter never forwards a mode:function storage(options = {}) { const store = new import_electron_store.default({ name: options.name ?? "clerk-tokens", ...options.path ? { cwd: options.path } : {} });so
electron-storegets noconfigFileModeandconf's0o666is passed as the writemode. On the app side,apps/desktop/src/app/DesktopClerk.ts:88is stillstorage: storage({ path: stateDir }), and a repo-wide grep forconfigFileMode/unencryptedFallback(excludingnode_modulesand the vendored.repos/directory) returns no application hits. So passing the mode throughstorage()is not possible today — this needs either aconfigFileModeoption in@clerk/electron/storageor an explicitchmodby the desktop app after the store is created (your "Suggested fix" first option, applied in our code).The
unencryptedFallback: truepart no longer matches what ships. I could not find it being passed. The bundled@clerk/electroncode warns about it as an opt-in the caller must request, and takes a memory fallback instead of writing plaintext when OS encryption is unavailable:Clerk: OS encryption is unavailable and unencryptedFallback is not enabled, so tokens are not being persisted. The user will be signed out on the next launch. Pass \storage({ unencryptedFallback: true })` to persist unencrypted (less secure).`storage({ path: stateDir })does not pass it, so the "wheresafeStorageis unavailable the session token is stored in plain text" impact does not hold for this version — Linux without a keyring should lose persistence rather than write plaintext, which I believe matches the behavior tracked in #9239 / #7689.On Windows the mode argument does not apply, but neither does any enforcement. Measured on Windows 11 (10.0.26200), after signing in to T3 Connect:
~/.t3/userdata/clerk-tokens.json— attributesArchive,IsReadOnly: False, and the value isenc:-prefixed (safeStorage ciphertext, 736 chars), so no plaintext token on disk here either.- Its ACL is three inherited ACEs only:
NT AUTHORITY\SYSTEM,BUILTIN\Administrators,<machine>\<user>— allFullControl/Allow/IsInherited=True. Nothing grantsBUILTIN\Usersread.
So the "any local user could read and replace it" consequence is macOS/Linux-specific. Worth noting for the fix, though: Node's
modeoption on Windows only toggles the read-only attribute and does not create ACLs, so aconfigFileMode: 0o600change buys nothing on Windows — the protection there comes entirely from the inherited%USERPROFILE%ACL, not from the app. If the intent is a guaranteed restrictive mode across platforms, the fix has to be mode + a documented statement about the Windows ACL source.Method: read-only inspection of the installed artifact (asar header parsed, each extracted member verified against its declared SHA-256) and static reading of the repo at
e3b35d1b2440; no runtime instrumentation, no token values captured.Independent confirmation on macOS 0.1.1 stable (release build, not nightly), plus one sibling file that #22190 does not appear to cover.
Confirmation on 0.1.1 stable#
Affected surface extends beyond nightly. Repro on a stock 0.1.1 install:
$ stat -f '%Sp %Mp%Lp' ~/.t3/userdata/clerk-tokens.json -rw-rw-rw- 0666 $ jq -r 'keys[]' ~/.t3/userdata/clerk-tokens.json __clerk_client_jwtThe process umask is
022, yet the file is0666— consistent with thechmod-based mechanism #22190 describes, and confirming that lowering umask is not a mitigation. The bundle contains bothconfigFileMode: 438andchmodSync(p, 438).Worth noting the correct pattern already exists in-tree: every credential under
~/.t3/userdata/secrets/is0700/0600, includingcloud-relay-environment-credential.bin.clerk-tokens.jsonwas the outlier because it sits outside that directory.Sibling file not covered by #22190#
cloud-auth-token.jsonlives in the same0755directory and is0644:$ stat -f '%Sp %Mp%Lp' ~/.t3 ~/.t3/userdata ~/.t3/userdata/cloud-auth-token.json drwxr-xr-x 0755 /Users/sadiq/.t3 drwxr-xr-x 0755 /Users/sadiq/.t3/userdata -rw-r--r-- 0644 /Users/sadiq/.t3/userdata/cloud-auth-token.json $ jq -r 'keys[]' ~/.t3/userdata/cloud-auth-token.json encryptedClientJwt versionThe contents are
encryptedClientJwt, so this is materially less severe than the0666Clerk store — the value is not usable without the OS keystore, and it is not writable by other local users. But it is still a token-bearing file readable by any local account, and #22190 scopes the new0700directory to the Clerk store only (grep finds no reference tocloud-auth-tokenin the diff).Suggestion: either move
cloud-auth-token.jsonunder the same0700directory as the Clerk tokens, or tighten~/.t3/userdataitself to0700. That would also cover the remaining0644files in there (connection-catalog.json,server-runtime.json) that carry account/environment identifiers.Not filing a separate issue since this is the same root cause and this thread already has a fix in flight.
maria-rcks closed this
Sign in to join this conversation.
Note
Grok responding on behalf of Julius.
Triage#
Thanks @MaximilianMauroner for the careful audit, and for checking the stored value's prefix! I confirmed this on current
main. The desktop Clerk bridge persists tokens withstorage({ path: stateDir })inapps/desktop/src/app/DesktopClerk.ts, and that call has passed only a path since the bridge was added. In@clerk/electron0.0.44,storage()forwards onlynameandcwdtoelectron-storeand doesn't accept a file mode.Why the file ends up
0666#electron-store8.2.0 usesconf10.2.0, whose defaultconfigFileModeis0o666. Writes go throughatomically.writeFileSync, whichchmods the temp file to that mode before renaming it into place.chmodisn't reduced by the umask, soclerk-tokens.jsonends up0666, not0644. Runningchmod 0600afterward doesn't stick, because everystore.setpassesmode: 0o666again and atomically doesn't keep a tighter mode.userdata/is created with a plainmkdirand isn't locked down the wayuserdata/secretsis (0700on the directory,0600on the files). With a typical0755home and state directory, another local user can open this file and overwrite its contents. Deleting it still requires write permission on the directory.Two corrections#
unencryptedFallback: true. Nothing in the repo sets that option, and@clerk/electrondefaults it tofalse. When OS encryption isn't available, the adapter keeps the token in memory and doesn't writeraw:<jwt>. Theenc:prefix you saw on your Mac fits that, so there's nounencryptedFallbackflag to remove.storage().getItemstill accepts a value that's already stored with theraw:prefix. Because the file is world-writable, someone could overwrite it with araw:token even though the app never opted into plaintext writes. That's the injection path. Reading anenc:value doesn't reveal the Keychain-protected JWT.Likely fix area#
storage()can't takeconfigFileMode, and a one-timechmodgets undone by the next atomic write. A durable fix would put the file in a directory created with mode0700before the store writes, or avoidconf's default mode some other way. ForwardingconfigFileModewould need an upstream@clerk/electronchange. A maintainer will decide on the fix direction.