Clear Codex app-server env keys case-insensitively on Windows (#73102) · openclaw/openclaw@78d51dc
pashpashpash
·
2026-04-29
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -112,6 +112,28 @@ describe("resolveCodexAppServerSpawnEnv", () => {
|
112 | 112 | }); |
113 | 113 | }); |
114 | 114 | |
| 115 | +it("clears denied env vars case-insensitively on Windows", () => { |
| 116 | +expect({ |
| 117 | + ...resolveCodexAppServerSpawnEnv( |
| 118 | +{ |
| 119 | +env: { |
| 120 | +OpenAI_Api_Key: "configured-openai-key", |
| 121 | +Other: "configured", |
| 122 | +}, |
| 123 | +clearEnv: ["OPENAI_API_KEY", " CODEX_API_KEY ", ""], |
| 124 | +}, |
| 125 | +{ |
| 126 | +Codex_Api_Key: "parent-codex-key", |
| 127 | +KEEP: "parent", |
| 128 | +}, |
| 129 | +"win32", |
| 130 | +), |
| 131 | +}).toEqual({ |
| 132 | +KEEP: "parent", |
| 133 | +Other: "configured", |
| 134 | +}); |
| 135 | +}); |
| 136 | + |
115 | 137 | it("uses a null-prototype env map and ignores prototype-polluting keys", () => { |
116 | 138 | const overrides = Object.create(null) as Record<string, string | undefined>; |
117 | 139 | Object.defineProperty(overrides, "__proto__", { |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -46,16 +46,38 @@ export function resolveCodexAppServerSpawnInvocation(
|
46 | 46 | export function resolveCodexAppServerSpawnEnv( |
47 | 47 | options: Pick<CodexAppServerStartOptions, "env" | "clearEnv">, |
48 | 48 | baseEnv: NodeJS.ProcessEnv = process.env, |
| 49 | +platform: NodeJS.Platform = process.platform, |
49 | 50 | ): NodeJS.ProcessEnv { |
50 | 51 | const env = Object.create(null) as NodeJS.ProcessEnv; |
51 | 52 | copySafeEnvironmentEntries(env, baseEnv); |
52 | 53 | copySafeEnvironmentEntries(env, options.env ?? {}); |
53 | | -for (const key of options.clearEnv ?? []) { |
54 | | -delete env[key]; |
| 54 | +const keysToClear = normalizedEnvironmentKeys(options.clearEnv ?? []); |
| 55 | +if (platform === "win32") { |
| 56 | +const lowerCaseKeysToClear = new Set(keysToClear.map((key) => key.toLowerCase())); |
| 57 | +for (const candidate of Object.keys(env)) { |
| 58 | +if (lowerCaseKeysToClear.has(candidate.toLowerCase())) { |
| 59 | +delete env[candidate]; |
| 60 | +} |
| 61 | +} |
| 62 | +} else { |
| 63 | +for (const key of keysToClear) { |
| 64 | +delete env[key]; |
| 65 | +} |
55 | 66 | } |
56 | 67 | return env; |
57 | 68 | } |
58 | 69 | |
| 70 | +function normalizedEnvironmentKeys(rawKeys: readonly string[]): string[] { |
| 71 | +const keys: string[] = []; |
| 72 | +for (const rawKey of rawKeys) { |
| 73 | +const key = rawKey.trim(); |
| 74 | +if (key.length > 0) { |
| 75 | +keys.push(key); |
| 76 | +} |
| 77 | +} |
| 78 | +return keys; |
| 79 | +} |
| 80 | + |
59 | 81 | function copySafeEnvironmentEntries( |
60 | 82 | target: NodeJS.ProcessEnv, |
61 | 83 | source: NodeJS.ProcessEnv | Record<string, string | undefined>, |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。