Skip to content

The agent that grows with you

fix(desktop): /config renders only the owner's client projection, failing closed

Tekniumbdbc0f5dabf8
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/slash-desktop-commands.test.tsx b/apps/desktop/src/app/session/hooks/use-prompt-actions/slash-desktop-commands.test.tsx
index 0b6f95a45ac..f47def41f1d 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/slash-desktop-commands.test.tsx
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/slash-desktop-commands.test.tsx
@@ -252,19 +252,78 @@ describe('/config', () => {
expect(text).toContain('Settings')
})
- it('never prints credentials or provider sections, whichever server answered', async () => {
+ it('renders the canonical projection in full', async () => {
+ const requestGateway = gateway(method =>
+ method === 'config.get'
+ ? {
+ config: {
+ display: { skin: 'mono', timestamps: true, details_mode: 'collapsed' },
+ approvals: { mode: 'manual', timeout: 60 },
+ paste_collapse_threshold: 5,
+ paste_collapse_char_threshold: 800,
+ voice: { record_key: 'ctrl+b', submit_mode: 'auto' }
+ }
+ }
+ : undefined
+ )
+
+ const handle = await mount(requestGateway)
+
+ await handle.submitText('/config')
+
+ const text = renderedText(handle)
+
+ for (const line of [
+ 'skin: mono',
+ 'timestamps: true',
+ 'details_mode: collapsed',
+ 'mode: manual',
+ 'timeout: 60',
+ 'paste_collapse_threshold: 5',
+ 'paste_collapse_char_threshold: 800',
+ 'record_key: ctrl+b',
+ 'submit_mode: auto'
+ ]) {
+ expect(text).toContain(line)
+ }
+ })
+
+ it('fails closed on a legacy raw config: only the canonical allowlist renders', async () => {
// A standalone `hermes serve` answers config.get key=full with the raw effective config.
+ const S = 'PROBE-SECRET'
+
const requestGateway = gateway(method =>
method === 'config.get'
? {
config: {
- model: { default: 'm', api_key: 'sk-PROBE-SECRET' },
- providers: { p: { api_key: 'sk-PROBE-SECRET' } },
- custom_providers: [{ name: 'c', api_key: 'sk-PROBE-SECRET' }],
- mcp_servers: { s: { env: { X: 'sk-PROBE-SECRET' } } },
- display: { skin: 'mono' },
- tools: { web: { api_key: 'sk-PROBE-SECRET', bearer_token: 'sk-PROBE-SECRET', backend: 'x' } },
- auth: { password: 'sk-PROBE-SECRET', client_secret: 'sk-PROBE-SECRET' }
+ model: { default: 'm', api_key: S },
+ providers: { p: { 'api-key': S } },
+ custom_providers: [{ name: 'c', api_key: S }],
+ mcp_servers: {
+ s: { headers: { Authorization: `Bearer ${S}`, 'X-Api-Key': S, Cookie: `sid=${S}` }, env: { X: S } }
+ },
+ FAL_KEY: S,
+ browser: { camofox: { session_key: S } },
+ terminal: {
+ ssh_private_key: S,
+ docker_shared_container_key: S,
+ docker_env: { DB_PASS: S, MY_CREDENTIALS: S }
+ },
+ tools: { web: { key: S, bearer: S, jwt: S, passwd: S, backend: 'x' } },
+ platforms: { hooks: [{ url: 'https://h', auth: `Bearer ${S}` }] },
+ display: {
+ skin: 'mono',
+ 'api-key': S,
+ key: S,
+ bearer: S,
+ jwt: S,
+ passwd: S,
+ session_key: S,
+ headers: { Authorization: S, 'X-Api-Key': S, Cookie: S },
+ image_url: `https://user:${S}@example.com/x`,
+ list: [{ auth: `Bearer ${S}`, keep: 'ok', url: `https://u:${S}@h.example/` }]
+ },
+ voice: { record_key: 'ctrl+b', api_key: S, provider: 'openai' }
}
}
: undefined
@@ -276,9 +335,15 @@ describe('/config', () => {
const text = renderedText(handle)
expect(text).toContain('skin: mono')
- expect(text).toContain('backend: x')
- expect(text).not.toContain('sk-PROBE-SECRET')
- expect(text).not.toMatch(/^\s*(model|providers|custom_providers|mcp_servers):/m)
+ expect(text).toContain('record_key: ctrl+b')
+ expect(text).toContain('https://example.com/x')
+ expect(text).toContain('"keep":"ok"')
+ expect(text).not.toContain(S)
+ expect(text).not.toContain('provider: openai')
+ expect(text).not.toContain('backend: x')
+ expect(text).not.toMatch(
+ /^\s*(model|providers|custom_providers|mcp_servers|FAL_KEY|browser|terminal|tools|platforms):/m
+ )
})
})
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/slash-desktop-commands.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/slash-desktop-commands.ts
index 0e394668c5b..3e72bc228e9 100644
--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/slash-desktop-commands.ts
+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/slash-desktop-commands.ts
@@ -200,30 +200,68 @@ function formatAgents(subagents: SubagentRow[], processes: ProcessRow[]): string
}
// A standalone `hermes serve` answers config.get key=full with the raw effective config, so the
-// renderer drops credentials and provider/MCP sections itself rather than trusting the server.
-const CONFIG_HIDDEN_SECTIONS = new Set(['custom_providers', 'mcp_servers', 'model', 'providers'])
-const CONFIG_SECRET_KEY = /api_?key|secret|password|(^|_)tokens?$/i
+// renderer fails closed: it prints only the sections the canonical owner projects
+// (gateway/session_config.py::_client_config) and omits everything else. Keep in sync.
+const CONFIG_ALLOWED: Record<string, true | readonly string[]> = {
+ display: true,
+ approvals: true,
+ paste_collapse_threshold: true,
+ paste_collapse_char_threshold: true,
+ voice: ['record_key', 'submit_mode']
+}
+
+// Leaf rule of hermes_cli/config.py::_is_secret_config_key (+ auth/cookie), applied inside
+// allowlisted sections (the owner masks these; a legacy server sends them raw).
+const CONFIG_SECRET_KEY =
+ /^(api_?key|key|auth|cookie|token|access_token|refresh_token|id_token|secret|client_secret|password|passwd|authorization|private_key|bearer|jwt)$|_(api_key|token|secret|password|key|access_key)$/
+
+const secretConfigKey = (key: string) => CONFIG_SECRET_KEY.test(key.toLowerCase().replace(/-/g, '_'))
+
+// `scheme://user:pass@host` -> `scheme://host`.
+const stripUserinfo = (value: string) => value.replace(/([a-z][a-z\d+.-]*:\/\/)[^/?#\s@]*@/gi, '$1')
+
+const scrubConfig = (key: string, value: unknown) =>
+ key && secretConfigKey(key) ? undefined : typeof value === 'string' ? stripUserinfo(value) : value
+
+function clientConfigProjection(config: Record<string, unknown>): Record<string, unknown> {
+ const out: Record<string, unknown> = {}
+
+ for (const [key, allowed] of Object.entries(CONFIG_ALLOWED)) {
+ const value = config[key]
+
+ if (value === undefined) {
+ continue
+ }
+
+ if (allowed === true) {
+ out[key] = value
+ } else if (value && typeof value === 'object' && !Array.isArray(value)) {
+ const section = value as Record<string, unknown>
+ out[key] = Object.fromEntries(allowed.filter(name => name in section).map(name => [name, section[name]]))
+ }
+ }
+
+ return out
+}
-const hiddenConfigKey = (key: string, top: boolean) =>
- CONFIG_SECRET_KEY.test(key) || (top && CONFIG_HIDDEN_SECTIONS.has(key))
+// `voice.record_key` is a keybinding the owner allowlists after masking, not a credential.
+const CONFIG_NOT_SECRET = new Set(['voice.record_key'])
-function yamlLines(value: unknown, indent = ''): string[] {
+function yamlLines(value: unknown, indent = '', path = ''): string[] {
if (value === null || typeof value !== 'object') {
- return [`${indent}${String(value)}`]
+ return [`${indent}${String(scrubConfig('', value))}`]
}
return Object.entries(value as Record<string, unknown>).flatMap(([key, child]) =>
- hiddenConfigKey(key, !indent)
+ secretConfigKey(key) && !CONFIG_NOT_SECRET.has(`${path}${key}`)
? []
: child !== null && typeof child === 'object' && !Array.isArray(child)
? Object.keys(child).length
- ? [`${indent}${key}:`, ...yamlLines(child, `${indent} `)]
+ ? [`${indent}${key}:`, ...yamlLines(child, `${indent} `, `${path}${key}.`)]
: []
: [
`${indent}${key}: ${
- Array.isArray(child)
- ? JSON.stringify(child, (k, v) => (k && CONFIG_SECRET_KEY.test(k) ? undefined : v))
- : String(child)
+ Array.isArray(child) ? JSON.stringify(child, scrubConfig) : String(scrubConfig('', child))
}`
]
)
@@ -338,11 +376,14 @@ export function desktopReadCommandHandlers<C extends { arg: string }>(env: Deskt
key: 'full'
})
- const body = result?.config && typeof result.config === 'object' ? yamlLines(result.config) : []
+ const body =
+ result?.config && typeof result.config === 'object' && !Array.isArray(result.config)
+ ? yamlLines(clientConfigProjection(result.config as Record<string, unknown>))
+ : []
out.render(
[
- 'Configuration (display settings; secrets and provider config are not shown):',
+ 'Configuration (display, approvals, paste and voice settings; everything else is not shown):',
...(body.length ? body : ['(defaults)']),
'',
'Change settings in Settings, or edit config.yaml with `hermes config edit` on the gateway host.'