Skip to content

Fix \init\ persisting env var API keys into config - #289

Open
mayuriphad wants to merge 1 commit into
404-PF:mainfrom
mayuriphad:fix-init-api-key
Open

Fix \init\ persisting env var API keys into config#289
mayuriphad wants to merge 1 commit into
404-PF:mainfrom
mayuriphad:fix-init-api-key

Conversation

@mayuriphad

@mayuriphad mayuriphad commented Aug 23, 2026

Copy link
Copy Markdown

Fixes #281 by tracking whether an existing key came from the config file or the environment, preventing environment variable API keys from being inadvertently saved to \config.json\ when the user leaves the prompt blank.

Review in cubic

Copilot AI lite review requested due to automatic review settings August 23, 2026 15:54

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0516005c-822d-4d5b-97fa-b05fd34eea3a


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/commands/init.ts">

<violation number="1" location="src/commands/init.ts:126">
P1: When `COMMIT_ECHO_API_KEY` supplies the effective key during reconfiguration, this assignment misclassifies it as a config key, so a blank prompt persists the environment secret. Read the raw config value before applying environment overrides, or track the override source when deciding what to save.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread src/commands/init.ts

if (needsApiKey) {
const existingKey = existingConfig?.apiKey ?? process.env[apiKeyEnv] ?? '';
const existingConfigKey = existingConfig?.apiKey ?? '';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1: When COMMIT_ECHO_API_KEY supplies the effective key during reconfiguration, this assignment misclassifies it as a config key, so a blank prompt persists the environment secret. Read the raw config value before applying environment overrides, or track the override source when deciding what to save.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/commands/init.ts, line 126:

<comment>When `COMMIT_ECHO_API_KEY` supplies the effective key during reconfiguration, this assignment misclassifies it as a config key, so a blank prompt persists the environment secret. Read the raw config value before applying environment overrides, or track the override source when deciding what to save.</comment>

<file context>
@@ -123,7 +123,8 @@ export async function initCommand(options: { installHook?: boolean } = {}): Prom
 
   if (needsApiKey) {
-    const existingKey = existingConfig?.apiKey ?? process.env[apiKeyEnv] ?? '';
+    const existingConfigKey = existingConfig?.apiKey ?? '';
+    const existingKey = existingConfigKey || process.env[apiKeyEnv] || '';
     const keyResult = await text(buildApiKeyPrompt(existingKey, apiKeyEnv));
</file context>

@404-Page-Found 404-Page-Found left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

High severity issue above

@mayuriphad

Copy link
Copy Markdown
Author

The fix in this PR's single commit (f1fa9cd) already addresses the flagged issue: existingConfigKey is now read separately from process.env[apiKeyEnv], and only existingConfigKey (not the env-var fallback) is persisted when the prompt is left blank. Re-checked line-by-line and confirmed a blank reconfig prompt no longer writes the env var's key into config.json. Could you take another look / re-review? Happy to add a regression test if useful.

@404-Page-Found

Copy link
Copy Markdown
Contributor

@cubic-dev-ai

@cubic-dev-ai

cubic-dev-ai Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai

@404-Page-Found I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 existing issue remains and no new issues found across 1 file

Requires human review: Auto-approval blocked by 1 unresolved issue from a previous review of this commit.

Re-trigger cubic

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.

[Security] init persists env-var API keys into config.json despite prompting "leave blank to use $ENV"

3 participants