Repository navigation
fix(desktop): store Clerk tokens with owner-only permissions (#22190) - #345
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Desktop Clerk stored sign-in tokens with
@clerk/electronstorage({ path: stateDir }). That adapter uses electron-store, andconfwritesclerk-tokens.jsonwithconfigFileMode0o666, so the process umask never tightens it and the next write restores0666. Another local user could read or replace the file.This is a narrow security cherry-pick of upstream pingdotgg/t3code#22190 (
bd9cc0a901). It is the first step in the phased plan, before any broader nightly sync (upstreamv0.1.6-nightly.20261031.3956@d92c437is not included). Do not merge this as part of a full upstream sync.Change
Cherry-picked
-xonlybd9cc0a901onto currentmain(42c296b48, Phase B through nightly20261030.3940/ #343).The store now lives in
<stateDir>/clerk, created at0700. Startup moves an existingclerk-tokens.jsoninto that directory and sets it to0600. The same mode is applied again after every storage read, write, and delete. A symlink directory or token file is rejected so chmod cannot follow it.Fork desktop identity is preserved. The only conflict was
createDesktopClerkBridge: this fork already passesenvironment.appVersioninto the desktop scheme, and the security fix also needsuserDataPath. Both arguments are kept. Publishable-key handling, product paths (shuv2code-v2), and deep-link schemes (shuv2code-dev/s2code-dev) are unchanged.Files
apps/desktop/src/app/ClerkTokenStore.ts(new)apps/desktop/src/app/ClerkTokenStore.test.ts(new)apps/desktop/src/app/DesktopClerk.tsapps/desktop/src/app/DesktopClerk.test.tsScope and approval
Security-only cherry-pick of the already-merged upstream fix for pingdotgg#22190 / pingdotgg#15143. No release, update, or desktop-identity changes, and no other nightly commits.
Verification
vp test run apps/desktop/src/app/ClerkTokenStore.test.ts apps/desktop/src/app/DesktopClerk.test.ts: 2 files, 27 passed (Linux). Upstream reported 25; this fork has two extra DesktopClerk cases.vp fmt --checkandvp linton the four files: passed.tsc --noEmitfor@t3tools/desktopand@t3tools/scripts: passed (vp run check:changedtypecheck).vp run check:changed: format, lint, typecheck, and the two tests passed. Knip failed on pre-existing unused files/exports that are not in this diff (scripts/resolve-nightly-release.ts, marketing@fontsource-variable/inter, and unused exports in desktop/server/web/shared identity helpers).Limitations, same as upstream: the mode unit test skips on win32, where Node's file mode only toggles the read-only attribute. electron-store still applies
0666during the write;0600is restored immediately afterward, and the0700directory covers that interval. Checked on Linux only.Model and harness: Grok 4.7 in a Cursor Cloud Agent.