Skip to content

fix(config): write config.toml readable by its owner only - #502

Merged
mrnasil merged 2 commits into
mainfrom
fix/config-write-perms
Nov 25, 2026
Merged

mrnasil merged 2 commits into
mainfrom
fix/config-write-perms

Conversation

@mrnasil

@mrnasil mrnasil commented Nov 25, 2026

Copy link
Copy Markdown
Member

config.toml can hold API keys; set_openrouter_api_key writes one there. write_atomic created its temp file with fs::write, which uses the umask mode, usually 0644. The rename then carried that mode over any 0600 file the user had set. On a shared Unix host, every local user could read the key.

The temp file is now set to 0600 before anything is written, the same as auth.json. A config left at 0644 by an older build is tightened on its next save. A temp file left behind by a crash is truncated and tightened too, rather than blocking saves. Windows is unchanged.

Test (Unix): a new config is 0600, a 0644 one becomes 0600 on save, and its contents are replaced. On Linux (WSL), all 166 config tests pass and load.rs has 100% line coverage.

🤖 Generated with Claude Code

config.toml can hold API keys (set_openrouter_api_key writes one). Its
temp file was created with fs::write and the umask mode, usually 0644,
and the rename carried that over any 0600 file the user had set, so on
a shared Unix host every local user could read the key. The temp file
is now set to 0600 before anything is written; auth.json already is.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mrnasil
mrnasil enabled auto-merge (squash) November 25, 2026 15:55
@mrnasil
mrnasil merged commit 133414b into main Nov 25, 2026
7 checks passed
@mrnasil
mrnasil deleted the fix/config-write-perms branch November 25, 2026 23:53
@mrnasil mrnasil mentioned this pull request Nov 26, 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