Repository navigation
Keep Codex subscription runs from inheriting API keys - #73063
Conversation
Greptile SummaryThis PR exposes the previously internal
Confidence Score: 3/5Not safe to merge until A single P1 security finding — sensitive env values (like the advertised
|
e6792b3 to
8c9db4e
Compare
8c9db4e to
3be14ca
Compare
|
Pushed follow-up What changed:
Verification:
|
5fe2b27 to
d890283
Compare
80a1023 to
dec5906
Compare
dec5906 to
06fdff1
Compare
|
Live smoke proof for the Codex auth isolation change: I ran three fresh local embedded agent sessions from this PR branch.
Command shape: Result: success. The JSON metadata reported
Command shape: Result: expected failure. The run exited 1 with
Command shape: Result: success. The JSON metadata reported That gives us the falsifiable end-to-end proof: the same bogus env key that breaks PI does not break Codex on this branch, because Codex is running through subscription auth instead of inherited API-key auth. |
06fdff1 to
d72da2a
Compare
d72da2a to
52fef79
Compare
🔒 Aisle Security AnalysisWe found 1 potential security issue(s) in this PR:
1. 🟡 Case-variant environment variables can bypass clearEnv on Windows (OPENAI_API_KEY/CODEX_API_KEY leak)
Description
On Windows, environment variables are case-insensitive, and Node's This undermines the security intent introduced in Vulnerable code: for (const key of options.clearEnv ?? []) {
delete env[key];
}Impact (Windows):
RecommendationPerform platform-aware, case-insensitive clearing on Windows (and optionally normalize keys). Example fix: function deleteEnvKey(env: NodeJS.ProcessEnv, key: string, platform: NodeJS.Platform) {
if (platform === "win32") {
const needle = key.toLowerCase();
for (const k of Object.keys(env)) {
if (k.toLowerCase() === needle) {
delete env[k];
}
}
} else {
delete env[key];
}
}
// ...
for (const key of options.clearEnv ?? []) {
deleteEnvKey(env, key.trim(), process.platform);
}Also consider normalizing/validating Analyzed PR: #73063 at commit Last updated on: 2026-04-27T23:50:52Z |
|
Landed via temp rebase onto
Thanks @pashpashpash! |
Some OpenClaw installs need
OPENAI_API_KEYin the Gateway environment for embeddings, PI, or direct OpenAI model calls, while native Codex app-server turns should use the user's Codex or ChatGPT subscription login. Before this, the stdio Codex child inherited the Gateway environment by default, so a shared key could silently steer Codex runs onto Platform API billing.This keeps the public
appServer.clearEnvknob, but makes the common switch automatic. OpenClaw now selects Codex app-server auth in the same shape users expect from/models: an explicit OpenClaw Codex auth profile first, then the app-server's existing account such as a local Codex CLI ChatGPT sign-in, thenCODEX_API_KEYandOPENAI_API_KEYonly for local stdio app-server fallback when no account is available and the app-server still needs OpenAI auth.When the selected Codex auth is subscription-style OAuth or token auth, OpenClaw removes both
CODEX_API_KEYandOPENAI_API_KEYfrom the spawned Codex child process. Explicit Codex API-key profiles and local no-account env fallback still use app-server login, so users who intentionally want Codex on API-key auth can choose that path without relying on accidental env inheritance. WebSocket app-server connections do not receive Gateway env API-key fallback, and local fallback reads the same effective stdio environment afterappServer.envandappServer.clearEnvhave been applied.The shared-client key uses a process-local HMAC for app-server environment values and auth tokens, so internal env overrides still produce distinct clients without putting raw values or reusable secret fingerprints into the key string. The stdio env merge now uses a null-prototype map and ignores prototype-polluting keys. The auth bridge and stdio transport coverage now exercise local/default subscription auth, explicit OAuth and token profiles, explicit API-key profiles, local stdio env fallback, effective env clearing, existing app-server accounts, websocket connections, and child-process env clearing.
The user story this needs to protect is simple: a user keeps a real
OPENAI_API_KEYin the OpenClaw Gateway environment because some features should use Platform billing, then switches their OpenAI model runtime to Codex because they expect ChatGPT or Codex subscription auth. Their Codex turns should not silently start spending through the inherited Gateway key. At the same time, a user who explicitly chooses PI or an API-key Codex profile should still get API-key behavior.I proved that story with a live end-to-end smoke on this branch. I used real OpenClaw agent turns, not just unit tests or source inspection, and shaped the smoke as a positive control, a negative control, and then the Codex target case.
First, PI with a validated OpenAI Platform key succeeded:
OPENAI_API_KEY=<valid> OPENCLAW_AGENT_RUNTIME=pi node scripts/run-node.mjs agent --agent main --session-id smoke-pi-20260427193445-69302 --model openai/gpt-5.4 --thinking low --message "Reply with exactly OPENCLAW_PI_SMOKE_20260427193445-69302 and nothing else." --local --jsonThe result was a successful agent turn. The JSON metadata reported
agentHarnessId: "pi", provideropenai, modelgpt-5.4, and the assistant returned exactlyOPENCLAW_PI_SMOKE_20260427193445-69302.Second, PI with a deliberately bogus API key failed the way it should:
OPENAI_API_KEY=sk-invalid-openclaw-smoke-... OPENCLAW_AGENT_RUNTIME=pi node scripts/run-node.mjs agent --agent main --session-id smoke-pi-invalid-20260427193647-70546 --model openai/gpt-5.4 --thinking low ... --local --jsonThat run exited with
401 Incorrect API key provided. This is the control that proves PI was genuinely using the env API-key route, not some already-authenticated local subscription path.Third, Codex with the same kind of bogus env keys succeeded:
OPENAI_API_KEY=sk-invalid-openclaw-smoke-... CODEX_API_KEY=sk-invalid-openclaw-smoke-... OPENCLAW_AGENT_RUNTIME=codex node scripts/run-node.mjs agent --agent main --session-id smoke-codex-20260427193718-70903 --model openai/gpt-5.4 --thinking low --message "Reply with exactly OPENCLAW_CODEX_SMOKE_20260427193718-70903 and nothing else." --local --jsonThe result was a successful Codex agent turn. The JSON metadata reported
agentHarnessId: "codex", provideropenai, modelgpt-5.4, and the assistant returned exactlyOPENCLAW_CODEX_SMOKE_20260427193718-70903. The Codex sidecar recorded a real Codex thread id,019dd14e-1df2-72e0-a494-7b1565d13412. The harness auth home reportedauth_mode: "chatgpt"with no stored OpenAI API key, andcodex login statusfor that same harness auth home reportedLogged in using ChatGPT.That is the important falsifiable proof: the same bogus env key that breaks PI does not break Codex on this branch. PI still uses API-key auth when told to, while Codex subscription auth no longer inherits Gateway API-key billing by accident.
I am confident this covers the user story because the smoke first proves the parent env key can make a real OpenAI turn succeed or fail through PI, then proves Codex survives the same poisoned parent env while using ChatGPT subscription auth. The current PR head has the same Codex runtime and auth codepaths as the live-smoked implementation; the later rebase only changed docs/changelog wording and added the boundary test fix that made the refreshed CI lane green.
Fixes #73057.