fix(cli/configure): write .env at mode 0o600 to protect LLM API keys#1969
Open
JAE0Y2N wants to merge 1 commit into
Open
fix(cli/configure): write .env at mode 0o600 to protect LLM API keys#1969JAE0Y2N wants to merge 1 commit into
JAE0Y2N wants to merge 1 commit into
Conversation
The `configure` subcommand prompts the user for their LLM provider API
keys (OPENAI_API_KEY, ANTHROPIC_API_KEY, AZURE_OPENAI_API_KEY, etc.) and
patches them into the `.env` file via `writeFile(filePath, content, "utf-8")`
with no `mode` option. On macOS and most Linux defaults (umask 022) that
lands the file at 0o644 — world-readable. Any local account or process
that can traverse the home / working directory can recover the keys and
use them under the user's account quota.
This commit:
- Adds `chmod` to the `fs/promises` import.
- Passes `{ encoding: "utf-8", mode: 0o600 }` to `writeFile` so a freshly-
created `.env` is atomically restricted to the user.
- Adds a follow-up `await chmod(filePath, 0o600)` (wrapped in try/catch
for Windows) so overwrites of a pre-existing `.env` at 0o644 converge
to 0o600 on the next save.
Mirrors industry-baseline credential-file handling (GitHub CLI's
~/.config/gh/hosts.yml, AWS CLI's ~/.aws/credentials at 0o600).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Author
|
@microsoft-github-policy-service agree |
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.
Summary
The
configuresubcommand atpackages/cli/src/configure.ts:186prompts the user for their LLM provider API keys and patches them into a.envfile viawriteFile(filePath, updatedLines.join(" "), "utf-8")with nomodeargument. On macOS and most Linux defaults (umask 022) the file lands at 0o644 — world-readable. Any local account or process that can traverse the working directory can recover the keys (OPENAI_API_KEY,ANTHROPIC_API_KEY,AZURE_OPENAI_API_KEY, etc.) and use them under the user's account quota.This PR adds
{ mode: 0o600 }to thewriteFilecall (applies on file creation) plus a follow-upchmod(filePath, 0o600)(wrapped intry/catchfor Windows) so pre-existing.envfiles at 0o644 converge to 0o600 on the next save.Files changed
packages/cli/src/configure.ts— addedchmodto thefs/promisesimport, passed{ encoding: "utf-8", mode: 0o600 }towriteFile, added a follow-upchmod.Verification
After the PR:
600.Context
Same CWE-732 finding class as
huggingface/huggingface_hub#4234(merged-approved),prisma/prisma#29568,eosphoros-ai/DB-GPT#3077,cline/cline#10893,replicate/cli#111,musistudio/claude-code-router#1399,anthropics/claude-cookbooks#642filed today across the AI-tooling ecosystem. Industry baseline (GitHub CLI / AWS CLI / Google Cloud SDK / Stripe CLI / Pulumi) is 0o600 for credential files.