Repository navigation
fix(electron): restrict the storage token file to owner-only access #9971
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
09523dd
55c603c
7c6c20e
ef031ab
a68df7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@clerk/electron': patch | ||
| --- | ||
|
|
||
| The token file written by `storage()` from `@clerk/electron/storage` is now readable and writable only by its owner (`0600`). It was previously world-readable (`0644` under the default umask). Existing token files are updated the next time `storage()` is called. | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,5 @@ | ||||||||||||||||||||||||||
| import { chmodSync } from 'node:fs'; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| import { safeStorage } from 'electron'; | ||||||||||||||||||||||||||
| import Store from 'electron-store'; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -125,8 +127,14 @@ async function resolveCipher(): Promise<Cipher | null> { | |||||||||||||||||||||||||
| export function storage(options: StorageOptions = {}): TokenStorage { | ||||||||||||||||||||||||||
| const store = new Store<Record<string, string>>({ | ||||||||||||||||||||||||||
| name: options.name ?? 'clerk-tokens', | ||||||||||||||||||||||||||
| configFileMode: 0o600, | ||||||||||||||||||||||||||
| ...(options.path ? { cwd: options.path } : {}), | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||
| chmodSync(store.path, 0o600); | ||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||
| /* the file does not exist yet, or it belongs to another user */ | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
wobsoriano marked this conversation as resolved.
Resolved
Comment on lines
+133
to
+137
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This
Suggested change
🤖 Generated with Claude Code |
||||||||||||||||||||||||||
| const memoryFallback = new Map<string, string>(); | ||||||||||||||||||||||||||
| // IPC requests can resolve out of order, so only the latest mutation may update storage. | ||||||||||||||||||||||||||
| const mutationVersions = new Map<string, number>(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: clerk/javascript
Length of output: 18681
Qualify the existing-file update claim.
storage()swallows everychmodSyncerror, not only a missing file. The next call can leave an existing token file at its previous mode, so the changeset should describe the update as an attempt.Proposed wording
markdownlint-cli2 (0.23.3)
[warning] 5-5: First line in a file should be a top-level heading
(MD041, first-line-heading, first-line-h1)