Skip to content

Commit 93f99ef

Browse files
Potential fix for code scanning alert no. 9: Clear-text storage of sensitive information
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent e6a74e4 commit 93f99ef

1 file changed

Lines changed: 12 additions & 28 deletions

File tree

teaagent/cli/_handlers/_misc.py

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,9 @@ def init_command(args: argparse.Namespace) -> int:
181181
cfg_path = tea_dir / 'config.json'
182182
cfg_path.write_text(json.dumps(config, sort_keys=True, indent=2), encoding='utf-8')
183183

184-
env_path = None
185-
if args.write_env and api_key:
186-
env_var = _provider_env_var(provider)
187-
env_path = tea_dir / 'env'
188-
existing = env_path.read_text(encoding='utf-8') if env_path.exists() else ''
189-
export_line = f'export {env_var}={api_key}\n'
190-
if export_line not in existing:
191-
env_path.write_text(existing + export_line, encoding='utf-8')
184+
env_var = _provider_env_var(provider)
185+
if api_key and env_var:
186+
os.environ[env_var] = api_key
192187

193188
payload = {
194189
'ok': True,
@@ -199,8 +194,8 @@ def init_command(args: argparse.Namespace) -> int:
199194
'max_iterations': int(args.max_iterations),
200195
'max_tool_calls': int(args.max_tool_calls),
201196
}
202-
if env_path is not None:
203-
payload['env_path'] = str(env_path)
197+
if args.write_env and api_key:
198+
payload['env_status'] = 'skipped clear-text env file write; key set for current process only'
204199
print_json(payload)
205200
return 0
206201

@@ -221,15 +216,7 @@ def configure_command(args: argparse.Namespace) -> int:
221216
print_json({'ok': True, 'message': 'all providers are already configured'})
222217
return 0
223218

224-
env_path = Path.home() / '.teaagent' / 'env'
225-
env_path.parent.mkdir(parents=True, exist_ok=True)
226-
227-
if env_path.exists():
228-
existing = env_path.read_text(encoding='utf-8')
229-
else:
230-
existing = ''
231-
232-
new_exports = ''
219+
configured_count = 0
233220
for provider, message in missing:
234221
env_var = _provider_env_var(provider)
235222
print(f'Provider {provider}: {message}')
@@ -241,21 +228,18 @@ def configure_command(args: argparse.Namespace) -> int:
241228
if not key:
242229
print(f' Skipped {provider} (empty input)')
243230
continue
244-
export_line = f'export {env_var}={key}\n'
245-
if export_line not in existing:
246-
new_exports += export_line
247-
os.environ[env_var] = key
231+
os.environ[env_var] = key
232+
configured_count += 1
248233

249-
if not new_exports:
250-
print_json({'ok': False, 'message': 'no keys were entered, nothing written'})
234+
if configured_count == 0:
235+
print_json({'ok': False, 'message': 'no keys were entered, nothing configured'})
251236
return 1
252237

253-
env_path.write_text(existing + new_exports, encoding='utf-8')
254238
print_json(
255239
{
256240
'ok': True,
257-
'message': f'wrote {env_path}',
258-
'hint': f'source {env_path} # add this to your shell profile for persistence',
241+
'message': f'configured {configured_count} provider(s) for current process only',
242+
'hint': 'keys were not written to disk to avoid clear-text secret storage',
259243
}
260244
)
261245
return 0

0 commit comments

Comments
 (0)