sec: clear wizard-set API keys from os.environ after session ends#25
Merged
rosspeili merged 1 commit intoMay 18, 2026
Merged
Conversation
Track env vars the CLI wizard adds for LiteLLM models and remove them in a finally block when the session loop ends, including on Ctrl+C. Pre-existing keys are never deleted. Adds unit tests for the tracking and cleanup helpers. Fixes ARPAHLS#5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes ARPAHLS/rooms#5.
When the CLI wizard collects an API key (e.g.
OPENAI_API_KEY), it writes intoos.environ. Those values previously persisted for the entire Python process, which is a security risk if the user runs another session in the same terminal or the process stays alive.This PR tracks only keys introduced by the wizard during setup and removes them when the session loop ends (normal exit,
exit/quit, orCtrl+C). Keys that were already set in the environment before the wizard runs are never touched.Changes
_set_session_env_key,_prompt_api_key_if_needed, and_cleanup_session_envincli.pytracked_env_keysfrommain_menuintorun_session_cleanup_session_envin afinallyblock after the session looptests/test_cli.pyfor tracking, skip-existing, and cleanup behaviorTest plan
.\venv\Scripts\python.exe -m pytest tests -q(15 passed)os.environfor that process