Skip to content

Commit ebc3ab8

Browse files
committed
fix(acp): strip provider API keys from ACP child process env
Provider API keys (e.g. OPENAI_API_KEY) injected by the auth system were leaking into ACP child processes. This caused Codex CLI to detect the env var and overwrite ~/.codex/auth.json, replacing OAuth credentials with apikey mode. The existing stripKeys mechanism only removed skill-injected env vars (getActiveSkillEnvKeys). This change also strips all known provider API key env vars (listKnownProviderEnvApiKeyNames) so ACP agents use their own configured authentication instead of inheriting leaked credentials. Fixes the same class of issue described in #36280.
1 parent 6b87489 commit ebc3ab8

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/acp/client.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,15 @@ export async function createAcpClient(opts: AcpClientOptions = {}): Promise<AcpC
459459
const serverCommand = opts.serverCommand ?? (entryPath ? process.execPath : "openclaw");
460460
const effectiveArgs = opts.serverCommand || !entryPath ? serverArgs : [entryPath, ...serverArgs];
461461
const { getActiveSkillEnvKeys } = await import("../agents/skills/env-overrides.runtime.js");
462-
const spawnEnv = resolveAcpClientSpawnEnv(process.env, {
463-
stripKeys: getActiveSkillEnvKeys(),
464-
});
462+
const { listKnownProviderEnvApiKeyNames } = await import("../agents/model-auth-env-vars.js");
463+
const stripKeys = new Set(getActiveSkillEnvKeys());
464+
// Strip provider API keys so they don't leak to ACP child processes.
465+
// Without this, env vars like OPENAI_API_KEY cause Codex CLI to overwrite
466+
// its OAuth credentials in ~/.codex/auth.json with apikey mode.
467+
for (const key of listKnownProviderEnvApiKeyNames()) {
468+
stripKeys.add(key);
469+
}
470+
const spawnEnv = resolveAcpClientSpawnEnv(process.env, { stripKeys });
465471
const spawnInvocation = resolveAcpClientSpawnInvocation(
466472
{ serverCommand, serverArgs: effectiveArgs },
467473
{

0 commit comments

Comments
 (0)