Description
Changing the configured provider does not clear or re-scope the existing API key. Both the interactive init flow and config set provider ... can carry a key issued for the old provider into the new provider configuration.
This can cause commit-echo to send a credential to the wrong upstream service, and it makes provider switches fail in confusing ways when the old credential is rejected.
Location
src/commands/init.ts:148-157 — promptApiKey()
src/commands/config.ts:86-101 — applyProviderChange()
Relevant code
// init.ts
const existingKey = existingConfig?.apiKey ?? process.env[provider.apiKeyEnv] ?? '';
...
return keyResult || existingKey || '';
// config.ts
function applyProviderChange(config: Config, provider: Config['provider']): Config {
const nextConfig = updateConfigField(config, 'provider', provider);
if (provider === CUSTOM_PROVIDER_KEY) return nextConfig;
return {
...nextConfig,
baseUrl: undefined,
};
}
The provider-change path clears baseUrl when appropriate, but leaves apiKey untouched. The init wizard also treats the existing stored key as reusable without checking whether it belongs to the newly selected provider.
Steps to Reproduce
- Configure provider A with API key A.
- Re-run
commit-echo init and switch to provider B.
- Leave the API-key prompt blank.
- The resulting config still contains API key A, and
resolveApiKey() uses the stored key for provider B.
- The same stale-key behavior is reproducible with
commit-echo config set provider <provider>.
Expected Behavior
A provider switch should require a key appropriate for the selected provider, or explicitly preserve a key only when the user confirms it is reusable. Stored credentials should not silently cross provider boundaries.
Actual Behavior
The previous provider's key is retained and can be sent to the new provider endpoint.
Suggested Fix
Track the provider that a stored credential belongs to, or clear apiKey whenever the provider changes and resolve the new provider's key from its configured environment variable. The init wizard should distinguish an existing key for the selected provider from a key belonging to another provider.
Impact
Provider reconfiguration can send the wrong secret to an unrelated third-party API endpoint and can leave the CLI configured with an invalid credential for the selected provider.
Reviewed against current main at 6c01ad0a853501e9617a3af0a5db3b515dd8ed53.
Description
Changing the configured provider does not clear or re-scope the existing API key. Both the interactive init flow and config set provider ... can carry a key issued for the old provider into the new provider configuration.
This can cause commit-echo to send a credential to the wrong upstream service, and it makes provider switches fail in confusing ways when the old credential is rejected.
Location
src/commands/init.ts:148-157—promptApiKey()src/commands/config.ts:86-101—applyProviderChange()Relevant code
The provider-change path clears
baseUrlwhen appropriate, but leavesapiKeyuntouched. The init wizard also treats the existing stored key as reusable without checking whether it belongs to the newly selected provider.Steps to Reproduce
commit-echo initand switch to provider B.resolveApiKey()uses the stored key for provider B.commit-echo config set provider <provider>.Expected Behavior
A provider switch should require a key appropriate for the selected provider, or explicitly preserve a key only when the user confirms it is reusable. Stored credentials should not silently cross provider boundaries.
Actual Behavior
The previous provider's key is retained and can be sent to the new provider endpoint.
Suggested Fix
Track the provider that a stored credential belongs to, or clear
apiKeywhenever the provider changes and resolve the new provider's key from its configured environment variable. The init wizard should distinguish an existing key for the selected provider from a key belonging to another provider.Impact
Provider reconfiguration can send the wrong secret to an unrelated third-party API endpoint and can leave the CLI configured with an invalid credential for the selected provider.
Reviewed against current
mainat6c01ad0a853501e9617a3af0a5db3b515dd8ed53.