Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(mcp-host): close CodeQL logger injection and property-write alerts

Alfredo Lopez84eb627b56bc
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index b2baff575..b659839cb 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.283",
+ "version": "0.1.284",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.283",
+ "version": "0.1.284",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@anthropic-ai/sdk": "^0.32.0",
diff --git a/mcp-host/package.json b/mcp-host/package.json
index 890a54720..91ba30c2c 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.283",
+ "version": "0.1.284",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --git a/mcp-host/src/llm/__tests__/registry.test.ts b/mcp-host/src/llm/__tests__/registry.test.ts
index 3597b3554..33eabb7bc 100644
--- a/mcp-host/src/llm/__tests__/registry.test.ts
+++ b/mcp-host/src/llm/__tests__/registry.test.ts
@@ -5,7 +5,7 @@
* the dev auto-detection priority order (§5.4/§5.9), the prototype-pollution
* guard in `isLlmProvider` (§1), and the factory fail-safe (§5.7).
*/
-import { describe, expect, it } from 'vitest'
+import { describe, expect, it, vi } from 'vitest'
import { apiKeysFromEnv, createLLMProvider } from '../index'
import { makeProvider } from '../registry'
import { ALL_PROVIDERS, descriptorFor, isLlmProvider, primarySlot } from '../registryCore'
@@ -123,6 +123,23 @@ describe('createLLMProvider — fail-safe (§5.7)', () => {
expect(result).toBeNull()
})
+ it('logs unknown providers without a format string or raw newlines', () => {
+ const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
+ createLLMProvider(
+ { openai: { 'openai-api-key': 'sk-test' } },
+ {
+ provider: 'mystery\n[injected]' as 'openai',
+ name: 'whatever',
+ }
+ )
+ const logged = spy.mock.calls.map(args => args.map(String).join(' ')).join('\n')
+ spy.mockRestore()
+ expect(logged).toContain('[LLM] Unknown provider:')
+ expect(logged).toContain('mystery')
+ expect(logged).not.toContain('%s')
+ expect(logged).not.toMatch(/mystery\n/)
+ })
+
it('returns null when the matching key is missing', () => {
const result = createLLMProvider(
{ claude: { 'claude-api-key': 'sk-claude' } },
diff --git a/mcp-host/src/llm/index.ts b/mcp-host/src/llm/index.ts
index 36272b562..a8b597648 100644
--- a/mcp-host/src/llm/index.ts
+++ b/mcp-host/src/llm/index.ts
@@ -21,6 +21,11 @@ export type { ClassifiedError, SingleTurnProvider } from './types'
const DEFAULT_CODEX_AUTHORIZE_GATEWAY =
'http://nginx-workflow-approval-gateway.control-plane.svc.cluster.local:8092'
+function sanitizeLogValue(value: unknown): string {
+ const raw = typeof value === 'string' ? value : String(value ?? '')
+ return JSON.stringify(raw.replace(/[\r\n\u2028\u2029]/g, ''))
+}
+
function createCodexRuntimeDeps() {
const gateway = (config.mcpHostGatewayUrl ?? '').trim() || DEFAULT_CODEX_AUTHORIZE_GATEWAY
return {
@@ -63,7 +68,7 @@ export function createLLMProvider(
const modelName = modelConfig?.name
if (!isLlmProvider(provider)) {
- console.error('[LLM] Unknown provider: %s', provider)
+ console.error('[LLM] Unknown provider: ' + sanitizeLogValue(provider))
return null
}
@@ -74,7 +79,13 @@ export function createLLMProvider(
const credentials = keys[provider] ?? {}
for (const slot of descriptorFor(provider).credentialSlots) {
if (slot.required && !credentials[slot.dataKey]) {
- console.error('[LLM] %s credential %s not found in secrets', provider, slot.dataKey)
+ console.error(
+ '[LLM] ' +
+ sanitizeLogValue(provider) +
+ ' credential ' +
+ sanitizeLogValue(slot.dataKey) +
+ ' not found in secrets'
+ )
return null
}
}
@@ -94,9 +105,10 @@ export function createLLMProvider(
)
} catch (err) {
console.error(
- '[LLM] failed to construct %s: %s',
- provider,
- err instanceof Error ? err.message : 'error'
+ '[LLM] failed to construct ' +
+ sanitizeLogValue(provider) +
+ ': ' +
+ sanitizeLogValue(err instanceof Error ? err.message : 'error')
)
return null
}
diff --git a/mcp-host/src/logger.test.ts b/mcp-host/src/logger.test.ts
index 7dbc0a97b..dace3953c 100644
--- a/mcp-host/src/logger.test.ts
+++ b/mcp-host/src/logger.test.ts
@@ -9,6 +9,18 @@ describe('mcp-host structured logger redaction', () => {
accessToken: '[Redacted]',
ok: true,
})
+ expect(
+ redactUnknown({ chatgptAccountId: 'acct_live', accountId: 'acct_live', ok: true })
+ ).toEqual({
+ chatgptAccountId: '[Redacted]',
+ accountId: '[Redacted]',
+ ok: true,
+ })
delete process.env.MCP_HOST_LOGGER_PROBE
})
+
+ it('drops prototype-polluting keys instead of writing them onto the clone', () => {
+ const input = { ok: true, constructor: { evil: true }, prototype: { evil: true } }
+ expect(redactUnknown(input)).toEqual({ ok: true })
+ })
})
diff --git a/mcp-host/src/logger.ts b/mcp-host/src/logger.ts
index 75321acc9..37c0f8e00 100644
--- a/mcp-host/src/logger.ts
+++ b/mcp-host/src/logger.ts
@@ -16,24 +16,30 @@
const COMPONENT_RE = /^\[([^\]]+)\]\s*/
const SENSITIVE_KEY_RE =
- /password|secret|token|authorization|cookie|api[_-]?key|dsn|private|refresh|credential/i
+ /password|secret|token|authorization|cookie|api[_-]?key|dsn|private|refresh|credential|account[_-]?id/i
+const UNSAFE_OBJECT_KEY = /^(?:__proto__|constructor|prototype)$/
const originalLog = console.log.bind(console)
const originalError = console.error.bind(console)
const originalWarn = console.warn.bind(console)
+function redactReplacer(key: string, value: unknown): unknown {
+ if (value === process.env) return '[Redacted]'
+ if (UNSAFE_OBJECT_KEY.test(key)) return undefined
+ if (key && SENSITIVE_KEY_RE.test(key)) return '[Redacted]'
+ return value
+}
+
export function redactUnknown(value: unknown, key?: string): unknown {
if (value === process.env) return '[Redacted]'
if (key && SENSITIVE_KEY_RE.test(key)) return '[Redacted]'
- if (Array.isArray(value)) return value.map(item => redactUnknown(item))
- if (value && typeof value === 'object') {
- const out: Record<string, unknown> = {}
- for (const [childKey, childValue] of Object.entries(value as Record<string, unknown>)) {
- out[childKey] = redactUnknown(childValue, childKey)
- }
- return out
+ if (value === undefined) return undefined
+ if (typeof value !== 'object' || value === null) return value
+ try {
+ return JSON.parse(JSON.stringify(value, redactReplacer)) as unknown
+ } catch {
+ return '[Unserializable]'
}
- return value
}
function formatArgs(args: unknown[]): string {
@@ -66,7 +72,7 @@ function emit(level: string, args: unknown[]): void {
entry.component = component
}
- const writer = level === 'error' ? originalError : originalLog
+ const writer = level === 'error' ? originalError : level === 'warn' ? originalWarn : originalLog
writer(JSON.stringify(entry))
}