Skip to content

Commit 3dc54de

Browse files
committed
fix(config-audit): fail closed for secret argv values
1 parent 2f9f883 commit 3dc54de

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

src/config/io.audit.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,14 @@ describe("config io audit helpers", () => {
322322
]);
323323
});
324324

325-
it("does not mask the next arg when a secret flag is followed by another option", () => {
325+
it("masks the next arg after a secret flag even when it looks like another option", () => {
326326
const argv = ["openclaw", "--token", "--port", "8080"];
327-
expect(redactConfigAuditArgv(argv)).toEqual(["openclaw", "--token", "--port", "8080"]);
327+
expect(redactConfigAuditArgv(argv)).toEqual(["openclaw", "--token", "***", "8080"]);
328+
});
329+
330+
it("redacts dash-leading secret values after bare secret flags", () => {
331+
const argv = ["openclaw", "--password", "-secret-value"];
332+
expect(redactConfigAuditArgv(argv)).toEqual(["openclaw", "--password", "***"]);
328333
});
329334

330335
it("does not mask when a secret flag is the final arg with no value", () => {

src/config/io.audit.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ function parseFlagName(arg: string): string | null {
7676
// 1. `--flag=value` form for any name matching the explicit list or the
7777
// suffix heuristic — mask the value half.
7878
// 2. value following a bare `--flag` form — emit `***` instead of the
79-
// next arg, but only when the candidate value does not itself look
80-
// like another option (`-`/`--` prefix). A bare `--token --port 8080`
81-
// is treated as a missing value, leaving `--port` and `8080` intact.
79+
// next arg, even if it starts with `-`. Command parsers accept
80+
// dash-leading values for required options, and this persistent audit
81+
// log should fail closed.
8282
// 3. fall back to redactToolPayloadText for everything else, which catches
8383
// `KEY=VALUE` env-style assignments, raw token shapes (sk-, ghp_, xox*,
8484
// gsk_, AIza*, npm_, Telegram bot tokens, PEM blocks, Bearer headers,
@@ -95,13 +95,8 @@ export function redactConfigAuditArgv(argv: readonly string[]): string[] {
9595
}
9696
if (redactNext) {
9797
redactNext = false;
98-
if (!current.startsWith("-")) {
99-
result.push("***");
100-
continue;
101-
}
102-
// The previous arg looked like a secret flag but was followed by
103-
// another option — treat as a missing value and fall through so the
104-
// current arg is processed normally.
98+
result.push("***");
99+
continue;
105100
}
106101
const currentFlag = parseFlagName(current);
107102
if (currentFlag !== null && isSecretFlagName(currentFlag)) {

0 commit comments

Comments
 (0)