mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 04:27:41 +00:00
fix(config): redact resolved field in config snapshots
The newly added 'resolved' field contains secrets after ${ENV}
substitution. This commit ensures redactConfigSnapshot also redacts
the resolved field to prevent credential leaks in config.get responses.
This commit is contained in:
committed by
Peter Steinberger
parent
3189e2f11b
commit
2a9745c9a1
@@ -12,6 +12,7 @@ function makeSnapshot(config: Record<string, unknown>, raw?: string): ConfigFile
|
|||||||
exists: true,
|
exists: true,
|
||||||
raw: raw ?? JSON.stringify(config),
|
raw: raw ?? JSON.stringify(config),
|
||||||
parsed: config,
|
parsed: config,
|
||||||
|
resolved: config as ConfigFileSnapshot["resolved"],
|
||||||
valid: true,
|
valid: true,
|
||||||
config: config as ConfigFileSnapshot["config"],
|
config: config as ConfigFileSnapshot["config"],
|
||||||
hash: "abc123",
|
hash: "abc123",
|
||||||
@@ -188,12 +189,23 @@ describe("redactConfigSnapshot", () => {
|
|||||||
expect(parsed.channels.discord.token).toBe(REDACTED_SENTINEL);
|
expect(parsed.channels.discord.token).toBe(REDACTED_SENTINEL);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("redacts resolved object as well", () => {
|
||||||
|
const config = {
|
||||||
|
gateway: { auth: { token: "supersecrettoken123456" } },
|
||||||
|
};
|
||||||
|
const snapshot = makeSnapshot(config);
|
||||||
|
const result = redactConfigSnapshot(snapshot);
|
||||||
|
const resolved = result.resolved as Record<string, Record<string, Record<string, string>>>;
|
||||||
|
expect(resolved.gateway.auth.token).toBe(REDACTED_SENTINEL);
|
||||||
|
});
|
||||||
|
|
||||||
it("handles null raw gracefully", () => {
|
it("handles null raw gracefully", () => {
|
||||||
const snapshot: ConfigFileSnapshot = {
|
const snapshot: ConfigFileSnapshot = {
|
||||||
path: "/test",
|
path: "/test",
|
||||||
exists: false,
|
exists: false,
|
||||||
raw: null,
|
raw: null,
|
||||||
parsed: null,
|
parsed: null,
|
||||||
|
resolved: {} as ConfigFileSnapshot["resolved"],
|
||||||
valid: false,
|
valid: false,
|
||||||
config: {} as ConfigFileSnapshot["config"],
|
config: {} as ConfigFileSnapshot["config"],
|
||||||
issues: [],
|
issues: [],
|
||||||
|
|||||||
@@ -137,12 +137,15 @@ export function redactConfigSnapshot(snapshot: ConfigFileSnapshot): ConfigFileSn
|
|||||||
const redactedConfig = redactConfigObject(snapshot.config);
|
const redactedConfig = redactConfigObject(snapshot.config);
|
||||||
const redactedRaw = snapshot.raw ? redactRawText(snapshot.raw, snapshot.config) : null;
|
const redactedRaw = snapshot.raw ? redactRawText(snapshot.raw, snapshot.config) : null;
|
||||||
const redactedParsed = snapshot.parsed ? redactConfigObject(snapshot.parsed) : snapshot.parsed;
|
const redactedParsed = snapshot.parsed ? redactConfigObject(snapshot.parsed) : snapshot.parsed;
|
||||||
|
// Also redact the resolved config (contains values after ${ENV} substitution)
|
||||||
|
const redactedResolved = redactConfigObject(snapshot.resolved);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...snapshot,
|
...snapshot,
|
||||||
config: redactedConfig,
|
config: redactedConfig,
|
||||||
raw: redactedRaw,
|
raw: redactedRaw,
|
||||||
parsed: redactedParsed,
|
parsed: redactedParsed,
|
||||||
|
resolved: redactedResolved,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user