Repository navigation
fix(config): write config.json owner-only - #1847
Josh Horecny (hank-sc0rpio) wants to merge 1 commit into
Conversation
The CLI config file holds the user's API token, but it was written with the default umask, which usually leaves it readable by every local user and by other jobs on a shared CI runner. Create the settings directory 0700 and config.json 0600 at open time. An existing config file is tightened to 0600 on the next save, before the new contents are written. Windows keeps its current behavior.
PR SummaryMedium Risk Overview Adds a Security changelog entry and unit tests (non-Windows) that assert directory/file modes and that a Reviewed by Cursor Bugbot for commit 36ca648. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 36ca648. Configure here.
| } finally { | ||
| closeSync(fd) | ||
| } | ||
| } |
There was a problem hiding this comment.
Failed chmod wipes saved config
Medium Severity
writeConfigFileSync opens config.json with 'w', which truncates it, before fchmodSync runs. If fchmodSync throws, the new contents are never written and the saved API token is already gone. That exception escapes the nextTick save and the CLI exits.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 36ca648. Configure here.


What
The CLI's
config.jsonholds the user's Socket API token as base64 JSON. It was written with the default umask, so on most systems it ended up-rw-r--r--. Any other local user, or another job on a shared CI runner, could read the token.This change:
~/.local/share/socket/settingsand the platform equivalents) with mode0700.config.jsonwith mode0600, so new files are owner-only from creation. The mode is not applied afterwards withchmod.0600withfchmodon the open handle before the new contents are written. Files left loose by earlier releases are fixed on the next save.I checked the other places the CLI writes credentials. The OAuth credential store already writes
0600files inside a0700directory, so it needs no change.Testing
file permissionscases intest/unit/src/utils/config.test.mts(skipped on Windows):0700/06000644file becomes0600on save, and its contents updatev1.xwithout this change and pass with it.pnpm test:unit test/unit/src/utils/config.test.mts: 19/19 pass.test/unit/src/commands/config: 28/28 pass.pnpm run lintandpnpm run check:tscpass.Manual check:
socket login, thenls -l ~/.local/share/socket/settings/config.jsonshows-rw-------.