Skip to content

fix(config): write config.json owner-only - #1847

Open
Josh Horecny (hank-sc0rpio) wants to merge 1 commit into
v1.xfrom
joshhorecny/config-perms-v1x
Open

Josh Horecny (hank-sc0rpio) wants to merge 1 commit into
v1.xfrom
joshhorecny/config-perms-v1x

Conversation

@hank-sc0rpio

@hank-sc0rpio Josh Horecny (hank-sc0rpio) commented Dec 4, 2026 •

Copy link
Copy Markdown

What

The CLI's config.json holds 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:

  • Creates the settings directory (~/.local/share/socket/settings and the platform equivalents) with mode 0700.
  • Opens config.json with mode 0600, so new files are owner-only from creation. The mode is not applied afterwards with chmod.
  • Tightens an existing config file to 0600 with fchmod on the open handle before the new contents are written. Files left loose by earlier releases are fixed on the next save.
  • Keeps current Windows behavior, where POSIX modes do not apply.

I checked the other places the CLI writes credentials. The OAuth credential store already writes 0600 files inside a 0700 directory, so it needs no change.

Testing

  • New file permissions cases in test/unit/src/utils/config.test.mts (skipped on Windows):
    • the settings directory and a new config file are created 0700 / 0600
    • an existing 0644 file becomes 0600 on save, and its contents update
  • These cases fail against v1.x without 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 lint and pnpm run check:tsc pass.

Manual check: socket login, then ls -l ~/.local/share/socket/settings/config.json shows -rw-------.

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.
@cursor

cursor Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Touches credential persistence on every config save; incorrect permission handling could break writes on some platforms, though scope is limited to config.mts and behavior on Windows is explicitly preserved.

Overview
Hardens on-disk permissions for persisted CLI settings that include the API token: the settings directory is now created as 0700, and config.json is written through a dedicated path that opens with 0600 and calls fchmod before writing on POSIX systems so existing world-readable files are tightened on the next save. Windows behavior is unchanged.

Adds a Security changelog entry and unit tests (non-Windows) that assert directory/file modes and that a 0644 config becomes 0600 when updated.

Reviewed by Cursor Bugbot for commit 36ca648. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread src/utils/config.mts
} finally {
closeSync(fd)
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 36ca648. Configure here.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant