Skip to content

fix(cli): create credential files 0600 from the start - #104

Merged
mr-kelly merged 1 commit into
mainfrom
fix/cli-credential-file-0600
Oct 27, 2026
Merged

mr-kelly merged 1 commit into
mainfrom
fix/cli-credential-file-0600

Conversation

@mr-kelly

Copy link
Copy Markdown
Contributor

Problem

writeEnvFileAt (apps/busabase-cli/src/config-file.ts) wrote the credential file with writeFileSync and only then called chmodSync(path, 0o600). With umask 022 a first login creates ~/.busabase/.env as 0644 holding the API key. Another local user who can traverse the home directory can open it in that window, and a descriptor opened then keeps working after the chmod.

Reported by the Omarchy plugin marketplace reviewer (omacom/omarchy-plugin-marketplace#12549).

Fix

  • Create the file with openSync(path, "w", 0o600), so it is never wider than 0600.
  • fchmodSync an already-existing looser file before the new secret is written.
  • Write through the descriptor rather than temp-file + rename, so a symlinked .env still points where it did.
  • Create parent directories 0700.
  • Only a filesystem with no POSIX modes (Windows, ENOSYS) may refuse the fchmod; any other error now surfaces instead of being swallowed.

Tests

New config-file-perms.test.ts, run under umask 022:

  • new .env is born 0600 (open called with mode 600), never via writeFileSync
  • an existing 0644 file is fchmoded to 0600 before the write (call order asserted, not just final mode)
  • ~/.busabase is 0700
  • a symlinked .env stays a symlink and the target is tightened

Against the previous code 4 of the 5 fail; with this change all pass. Whole CLI suite: 470 passed. tsc --noEmit and biome clean.

Not in this PR

No version bump. Publishing is publish-npm.yml on push to main, so the release version is the maintainer's call (suggest 0.99.2). The Omarchy plugin pins [email protected] and will move to the fixed release once it is on npm.

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