Skip to content

Commit 7e998a3

Browse files
steipeteampagent
andauthored
fix(cli): avoid exposing provider env values in parse errors (#124714)
* fix(cli): omit provider env values from parse errors Amp-Thread-ID: https://ampcode.com/threads/T-01a00ae0-190d-718b-8a76-b75f3e8d1fae * fix(config): redact provider env guidance Amp-Thread-ID: https://ampcode.com/threads/T-01a00ae0-190d-718b-8a76-b75f3e8d1fae * fix(config): redact provider env audit arguments --------- Co-authored-by: Amp <[email protected]>
1 parent 784dba0 commit 7e998a3

4 files changed

Lines changed: 55 additions & 3 deletions

File tree

‎src/cli/config-cli-input.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ function parseProviderEnvEntries(
161161
for (const entry of entries) {
162162
const separator = entry.indexOf("=");
163163
if (separator <= 0) {
164-
throw new Error(`--provider-env expects KEY=VALUE entries (received: "${entry}").`);
164+
throw new Error("--provider-env expects KEY=*** entries.");
165165
}
166166
const key = entry.slice(0, separator).trim();
167167
if (!key) {
168-
throw new Error(`--provider-env key must not be empty (received: "${entry}").`);
168+
throw new Error("--provider-env key must not be empty.");
169169
}
170170
env[key] = entry.slice(separator + 1);
171171
}

‎src/cli/config-cli.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,6 +1995,43 @@ describe("config cli", () => {
19951995
expect(mockWriteConfigFile).not.toHaveBeenCalled();
19961996
});
19971997

1998+
it.each([
1999+
[
2000+
"leading equals",
2001+
"=SYNTHETIC_PROVIDER_ENV_SECRET",
2002+
"--provider-env expects KEY=*** entries.",
2003+
],
2004+
[
2005+
"whitespace key",
2006+
" =SYNTHETIC_PROVIDER_ENV_SECRET",
2007+
"--provider-env key must not be empty.",
2008+
],
2009+
])("does not disclose provider env values for a %s entry", async (_name, entry, message) => {
2010+
const secret = "SYNTHETIC_PROVIDER_ENV_SECRET";
2011+
2012+
await expect(
2013+
runConfigCommand([
2014+
"config",
2015+
"set",
2016+
"secrets.providers.runner",
2017+
"--provider-source",
2018+
"exec",
2019+
"--provider-command",
2020+
"/usr/bin/env",
2021+
"--provider-env",
2022+
entry,
2023+
"--dry-run",
2024+
]),
2025+
).rejects.toThrow(message);
2026+
2027+
expect(mockReadConfigFileSnapshot).not.toHaveBeenCalled();
2028+
expect(mockWriteConfigFile).not.toHaveBeenCalled();
2029+
expect(JSON.stringify(mockLog.mock.calls)).not.toContain(secret);
2030+
expect(JSON.stringify(mockWriteStdout.mock.calls)).not.toContain(secret);
2031+
expect(JSON.stringify(mockError.mock.calls)).not.toContain(secret);
2032+
expectErrorIncludes(message);
2033+
});
2034+
19982035
it("runs resolvability checks in builder dry-run mode without writing", async () => {
19992036
setGatewaySnapshot({ providers: { default: { source: "env" } } });
20002037

‎src/config/io.audit.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,11 @@ describe("config io audit helpers", () => {
377377
argv: ["openclaw", "--password", "-fake"],
378378
expected: ["openclaw", "--password", "***"],
379379
},
380+
{
381+
name: "password alias covered by the secret suffix matcher",
382+
argv: ["openclaw", "--passwd", "fake"],
383+
expected: ["openclaw", "--passwd", "***"],
384+
},
380385
{
381386
name: "secret flag without a value",
382387
argv: ["openclaw", "--token"],
@@ -475,6 +480,16 @@ describe("config io audit helpers", () => {
475480
],
476481
expected: ["openclaw", "config", "set", "--batch-json", "***"],
477482
},
483+
{
484+
name: "config provider env assignment",
485+
argv: ["openclaw", "config", "set", "--provider-env", "KEY=secret-value"],
486+
expected: ["openclaw", "config", "set", "--provider-env", "***"],
487+
},
488+
{
489+
name: "inline config provider env assignment",
490+
argv: ["openclaw", "config", "set", "--provider-env=KEY=secret-value"],
491+
expected: ["openclaw", "config", "set", "--provider-env=***"],
492+
},
478493
])("redacts $name in persisted audit process info", ({ argv, expected }) => {
479494
expect(createAuditRecordBase("/tmp/openclaw.json", argv).argv).toEqual(expected);
480495
});

‎src/config/redact-argv.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const SECRET_FLAG_NAMES = new Set([
99
"--apikey",
1010
"--secret",
1111
"--password",
12-
"--passwd",
12+
"--provider-env",
1313
"--auth-token",
1414
"--access-token",
1515
"--refresh-token",

0 commit comments

Comments
 (0)