Fix: token fallback file briefly world-readable before chmod#76
Open
karbassi wants to merge 1 commit into
Open
Fix: token fallback file briefly world-readable before chmod#76karbassi wants to merge 1 commit into
karbassi wants to merge 1 commit into
Conversation
The file-based session fallback wrote the long-lived Monarch token via Path.write_text() (created under the process umask, typically 0644) and only narrowed it to 0600 afterward. That leaves a window where a full-access financial credential is world-readable by other local users. Create the file already locked via os.open(..., O_CREAT, 0o600), keeping the trailing chmod to enforce 0600 on a pre-existing file. Adds a regression test that fails if creation reverts to write_text(). Fixes robcerda#75 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
What
Closes #75.
The file-based session fallback (used when no keyring backend is available — WSL, headless Linux) wrote the long-lived Monarch session token via
Path.write_text()and narrowed permissions to0600only afterward:write_text()creates the file under the process umask (commonly0644), so between the write and thechmodthe token is world-readable by any local user. The payload is a long-lived, full-access financial credential, so the window is worth closing.How
Create the file already locked to
0600viaos.open(..., O_CREAT, 0o600), then stillchmodto enforce0600if the file already existed. No behavior change for keyring users (unaffected path).Test
Adds
TestFileFallbackPermissions, which intercepts creation and fails if the token file is created viawrite_text()or with any mode other than0600. Verified the test fails against the old implementation and passes with the fix.🤖 Generated with Claude Code