Fix \init\ persisting env var API keys into config - #289
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 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. Comment |
|
There was a problem hiding this comment.
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
|
|
||
| if (needsApiKey) { | ||
| const existingKey = existingConfig?.apiKey ?? process.env[apiKeyEnv] ?? ''; | ||
| const existingConfigKey = existingConfig?.apiKey ?? ''; |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
High severity issue above
|
The fix in this PR's single commit (f1fa9cd) already addresses the flagged issue: |
|
@404-Page-Found I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
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



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.