Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix(tui): fully mask sensitive config values as ******

ldstyle84d36a08889f5
diff --git a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/config.ts b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/config.ts
index 73bea506f9..8c701fb6df 100644
--- a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/config.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/config.ts
@@ -81,9 +81,8 @@ function flattenConfigEntries(
return flattened.length > 0 ? flattened : prefix ? [{ label: prefix, value: "{}" }] : [];
}
-function maskSensitive(value: string): string {
- if (!value || value.length <= 8) return "***";
- return `${value.slice(0, 4)}****${value.slice(-4)}`;
+function maskSensitive(_value: string): string {
+ return "******";
}
function groupConfigSchemaByGroup(
@@ -121,7 +120,7 @@ async function applyConfigSet(
title: "Config Updated",
items: [
{ label: "key", value: key },
- { label: "value", value: schema.sensitive ? "***" : value },
+ { label: "value", value: schema.sensitive ? "******" : value },
{ label: "applied", value: String(result.applied_without_restart) },
],
},
@@ -149,6 +148,17 @@ function buildConfigDisplayItems(
displayPayload[k] = v;
}
}
+ // 敏感项一律 mask 为 ******,避免 /config get 泄露明文密钥
+ const sensitiveKeys = new Set(
+ (payload.schema ?? []).filter((s) => s.sensitive).map((s) => s.key),
+ );
+ for (const k of Object.keys(displayPayload)) {
+ if (sensitiveKeys.has(k)) {
+ const raw = displayPayload[k];
+ const text = typeof raw === "string" ? raw : raw === null || raw === undefined ? "" : String(raw);
+ displayPayload[k] = text ? "******" : text;
+ }
+ }
// 若用户指定了 key 但后端未返回该字段,应明确提示未找到,而不是 fallback 回全部配置
if (key) {
if (displayPayload[key] === undefined) {
diff --git a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
index 3200bbe453..5328c895a2 100644
--- a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
@@ -1580,7 +1580,7 @@ function formatConfigValue(schema: ConfigItemSchema, val: string): string {
}
if (schema.sensitive) {
if (!val) return "(空)";
- return val.length > 8 ? `${val.slice(0, 4)}****${val.slice(-4)}` : "***";
+ return "******";
}
return val || "(空)";
}
@@ -7868,7 +7868,7 @@ export class AppScreen implements Component, Focusable {
currentValues: Record<string, string>,
): Promise<void> {
const isReset = this.configEditorState?.mode === "reset";
- const valueDisplay = schema.sensitive ? "***" : value;
+ const valueDisplay = schema.sensitive ? "******" : value;
const statusLabel = isReset ? "已重置" : "已应用";
const restartLabel = isReset ? "已重置(需重启)" : "需重启";
@@ -8208,7 +8208,7 @@ export class AppScreen implements Component, Focusable {
schema.type === "toggle"
? val === "true" ? "Enabled" : "Disabled"
: schema.sensitive
- ? val.length > 8 ? `${val.slice(0, 4)}****${val.slice(-4)}` : "***"
+ ? val ? "******" : "(empty)"
: val || "(empty)";
items.push({
value: schema.key,