fix: isolate profile .env secrets on switch - #351
Conversation
…le isolation The profile env isolation in _reload_dotenv now clears previously tracked env keys before re-reading .env. When apply_onboarding_setup set os.environ BEFORE _reload_dotenv, the key was immediately cleared. Move the belt-and-braces os.environ set to AFTER _reload_dotenv so the API key survives regardless of profile tracking state. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Full Review: PR #351 — isolate profile .env secrets on switchThanks @Hinotoi-agent! Real security fix — API keys from profile A were leaking into profile B on switch. Security AuditClean and positive. The change tracks which env vars were loaded from a profile's Code Review
CI Failure — Found and FixedCI was failing because Root cause: Fix pushed: Moved the belt-and-braces Tests759 passed, 0 failed, 48 skipped — all clean after the fix. The 2 new profile isolation tests are well-structured:
VerdictApproved. Fix pushed directly to the branch. CI should pass now. |
|
@Hinotoi-agent can you confirm this is working on the latest version? |
|
Yes — I validated it on the PR head commit |
* fix: isolate profile .env secrets on switch * fix: move direct os.environ set after _reload_dotenv to survive profile isolation The profile env isolation in _reload_dotenv now clears previously tracked env keys before re-reading .env. When apply_onboarding_setup set os.environ BEFORE _reload_dotenv, the key was immediately cleared. Move the belt-and-braces os.environ set to AFTER _reload_dotenv so the API key survives regardless of profile tracking state. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Nathan Esquenazi <nesquena@gmail.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* fix: isolate profile .env secrets on switch * fix: move direct os.environ set after _reload_dotenv to survive profile isolation The profile env isolation in _reload_dotenv now clears previously tracked env keys before re-reading .env. When apply_onboarding_setup set os.environ BEFORE _reload_dotenv, the key was immediately cleared. Move the belt-and-braces os.environ set to AFTER _reload_dotenv so the API key survives regardless of profile tracking state. --------- Co-authored-by: Nathan Esquenazi <nesquena@gmail.com>
Summary
.envvariables before loading the next profile.envkeys across profilesWhy this matters
The profile system is expected to isolate credentials and configuration between profiles.
Before this change, switching from one profile to another only added variables from the new profile's
.env; it did not clear variables that had been loaded from the previous profile. That allowed provider API keys and other secrets to persist into the new profile context.Root cause
api.profiles._reload_dotenv()loaded.envfiles additively intoos.environand never removed keys loaded from the previously active profile.Fix
.envTest plan
python -m pytest tests/test_profile_env_isolation.py -qpython -m pytest tests/test_auth_sessions.py -q