Skip to content

Commit a8d164f

Browse files
committed
fix: redact diagnostics config with schema hints
1 parent 6e4670f commit a8d164f

3 files changed

Lines changed: 69 additions & 1 deletion

File tree

‎src/logging/diagnostic-support-export.test.ts‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ describe("diagnostic support export", () => {
6262
].join(".");
6363
const privateChat = "private user said diagnose my bank transfer";
6464
const webhookBody = "raw webhook body with message contents";
65+
const requestAuthValue = "support-request-auth-value";
66+
const requestTlsPassphrase = "support-request-tls-passphrase";
67+
const proxyTlsPassphrase = "support-proxy-tls-passphrase";
6568
const credentialUrl =
6669
"wss://support-user:[email protected]/ws?token=short-token&ok=1";
6770
const configPath = path.join(tempDir, "openclaw.json");
@@ -81,6 +84,31 @@ describe("diagnostic support export", () => {
8184
logging: {
8285
redactSensitive: "off",
8386
},
87+
models: {
88+
providers: {
89+
supportProxy: {
90+
baseUrl: "https://models.example.test/v1",
91+
request: {
92+
auth: {
93+
mode: "header",
94+
headerName: "X-Support-Auth",
95+
value: requestAuthValue,
96+
},
97+
tls: {
98+
passphrase: requestTlsPassphrase,
99+
},
100+
proxy: {
101+
mode: "explicit-proxy",
102+
url: "http://127.0.0.1:8080",
103+
tls: {
104+
passphrase: proxyTlsPassphrase,
105+
},
106+
},
107+
},
108+
models: [{ id: "support-model" }],
109+
},
110+
},
111+
},
84112
channels: {
85113
telegram: {
86114
accounts: {
@@ -264,6 +292,10 @@ describe("diagnostic support export", () => {
264292
expect(combined).not.toContain("QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
265293
expect(combined).not.toContain("sid=secret");
266294
expect(combined).not.toContain("structured secret payload");
295+
expect(combined).not.toContain(requestAuthValue);
296+
expect(combined).not.toContain(requestTlsPassphrase);
297+
expect(combined).not.toContain(proxyTlsPassphrase);
298+
expect(combined).not.toContain("__OPENCLAW_REDACTED__");
267299
expect(combined).not.toContain("gateway-session-15555551212");
268300
expect(combined).not.toContain("supportEventSecret");
269301
expect(combined).not.toContain(fakeAwsKey);
@@ -365,6 +397,25 @@ describe("diagnostic support export", () => {
365397
redactSensitive?: string;
366398
};
367399
agents?: Array<{ name?: string; instructions?: string }>;
400+
models?: {
401+
providers?: {
402+
supportProxy?: {
403+
request?: {
404+
auth?: {
405+
value?: string;
406+
};
407+
tls?: {
408+
passphrase?: string;
409+
};
410+
proxy?: {
411+
tls?: {
412+
passphrase?: string;
413+
};
414+
};
415+
};
416+
};
417+
};
418+
};
368419
};
369420
expect(sanitizedConfig.gateway).toEqual({
370421
mode: "local",
@@ -376,6 +427,15 @@ describe("diagnostic support export", () => {
376427
},
377428
});
378429
expect(sanitizedConfig.logging?.redactSensitive).toBe("off");
430+
expect(sanitizedConfig.models?.providers?.supportProxy?.request?.auth?.value).toBe(
431+
"<redacted>",
432+
);
433+
expect(sanitizedConfig.models?.providers?.supportProxy?.request?.tls?.passphrase).toBe(
434+
"<redacted>",
435+
);
436+
expect(sanitizedConfig.models?.providers?.supportProxy?.request?.proxy?.tls?.passphrase).toBe(
437+
"<redacted>",
438+
);
379439
expect(Object.keys(sanitizedConfig.channels?.telegram?.accounts ?? {})).toEqual([
380440
"<redacted-account-1>",
381441
]);

‎src/logging/diagnostic-support-export.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { asOptionalRecord } from "@openclaw/normalization-core/record-coerce";
66
import { parseConfigJson5 } from "../config/io.js";
77
import { resolveConfigPath, resolveStateDir } from "../config/paths.js";
88
import { redactConfigObject } from "../config/redact-snapshot.js";
9+
import { buildConfigSchema } from "../config/schema.js";
910
import { resolveHomeRelativePath } from "../infra/home-dir.js";
1011
import { VERSION } from "../version.js";
1112
import {
@@ -291,7 +292,10 @@ function sanitizeConfigShape(
291292
}
292293

293294
function sanitizeConfigDetails(parsed: unknown, redaction: SupportRedactionContext): unknown {
294-
return sanitizeSupportConfigValue(redactConfigObject(parsed), redaction);
295+
return sanitizeSupportConfigValue(
296+
redactConfigObject(parsed, buildConfigSchema().uiHints),
297+
redaction,
298+
);
295299
}
296300

297301
function configShapeReadFailure(params: {

‎src/logging/diagnostic-support-redaction.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import path from "node:path";
33
import { isSensitiveUrlQueryParamName } from "@openclaw/net-policy/redact-sensitive-url";
44
import { asOptionalRecord } from "@openclaw/normalization-core/record-coerce";
5+
import { REDACTED_SENTINEL } from "../config/redact-snapshot.js";
56
import { isSecretRefShape } from "../config/redact-snapshot.secret-ref.js";
67
import { isBlockedObjectKey } from "../infra/prototype-keys.js";
78
import { redactSensitiveText } from "./redact.js";
@@ -429,6 +430,9 @@ export function sanitizeSupportConfigValue(
429430
return isPrivateConfigField(key) ? "<redacted>" : value;
430431
}
431432
if (typeof value === "string") {
433+
if (value === REDACTED_SENTINEL) {
434+
return "<redacted>";
435+
}
432436
return isPrivateConfigField(key) ? "<redacted>" : redactSupportString(value, redaction);
433437
}
434438
if (depth >= MAX_SUPPORT_SNAPSHOT_DEPTH) {

0 commit comments

Comments
 (0)