Skip to content

fix(auth): write the token store owner-only from the start and lock updates - #530

Merged
mrnasil merged 5 commits into
mainfrom
fix/auth-store-write
Dec 2, 2026
Merged

mrnasil merged 5 commits into
mainfrom
fix/auth-store-write

Conversation

@mrnasil

@mrnasil mrnasil commented Dec 2, 2026

Copy link
Copy Markdown
Member

From the same source audit as #527, #528 and #529.

Problem

auth.json was written to a fixed-name temp file (auth.json.tmp) and narrowed to 0600 only afterwards. Until then the tokens were readable under the directory's permissions and the default umask, and two writers shared one temp name. set and remove are read-modify-write with no lock, so a login in one process and a token refresh in another could drop each other's update.

Change

  • The temp file is created 0600 (Unix) under a name unique to the process and the write, then renamed over the store. A failed write removes it.
  • set and remove hold auth.json.lock (an advisory lock, released when the call returns) across the read-modify-write.

Windows is unchanged for permissions: the store relies on the per-user data directory there, as before.

Verification

  • New tests: the file is 0600, a failed replace leaves no temp file, eight concurrent writers keep all eight entries, an unusable lock path reports an I/O error.
  • Linux line coverage of whycodes-auth measured locally: no missed lines.

🤖 Generated with Claude Code

…pdates

The store was written to a fixed-name temp file and narrowed to 0600
afterwards, so the tokens were briefly readable under the default umask, and
two writers shared the temp name. The temp file is now created 0600 under a
unique name. set and remove hold a lock file across their read-modify-write,
so two processes (a login and a token refresh) no longer lose an update.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@mrnasil
mrnasil merged commit a449853 into main Dec 2, 2026
7 checks passed
@mrnasil
mrnasil deleted the fix/auth-store-write branch December 2, 2026 18:34
@mrnasil mrnasil mentioned this pull request Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant