fix(exec): honor Env override and keep secrets out of debug logs - #15
Merged
Merged
Conversation
ProcessStartInfo.Environment is pre-populated from the parent process, so writing the override on top of it leaked every inherited variable into the Codex CLI. The override is now applied after clearing that dictionary, and the parent environment is only inherited when no override is given. The debug log previously printed every variable's value, which exposed secrets such as CODEX_API_KEY; it now records variable names only. Also resolve the executable path once per CodexExec instead of on each run, since on Windows it probes every PATH directory, move logging to source-generated LoggerMessage methods, and use Environment.ProcessPath in place of the Process.GetCurrentProcess() workaround.
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.
ProcessStartInfo.Environmentbefore applyingCodexOptions.Env, so the override replaces the parent environment as documented instead of extending itCODEX_API_KEY) are no longer written to the debug logCodexExeclogging to[LoggerMessage]; the start message is only formatted when Debug is enabledCodexExecinstead of on every run (on Windows it probes every PATH directory), and useEnvironment.ProcessPathinstead ofProcess.GetCurrentProcess().MainModuleApplyEnvironmenttests for the override and inherit cases;FakeCodexClinow passes the parent environment explicitly, since the fake CLI is a .NET apphost that needs it to locate the runtimeBehavior change
Callers that set
CodexOptions.Envno longer inherit the parent environment (PATH,HOME,DOTNET_ROOT, ...). Anyone relying on the old behavior must now include those variables inEnv. The debug log placeholder{Environment}is renamed to{EnvironmentKeys}.Before the fix, the new test reproduces the leak:
Validation
dotnet test --solution codexsdk.slnx: total 52, failed 0, succeeded 52, skipped 0.Not included
System.Text.Json source generation for event parsing was evaluated and dropped: because the event DTOs use
initaccessors, it was ~15–20% slower than reflection and allocated more per event.