Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(rpc-proxy,host): strip control characters from logged hostRef and rebuild the wrapper flag
Alfredo Lopezae5082bbaa56
diff --git a/external-rest-api/src/releaseManifest.ts b/external-rest-api/src/releaseManifest.tsindex ff255b2ae..2ad1eee29 100644--- a/external-rest-api/src/releaseManifest.ts+++ b/external-rest-api/src/releaseManifest.ts@@ -9,7 +9,7 @@ export type ReleaseManifest = {export const releaseManifest: ReleaseManifest = {releaseId: 'v0.10.0',externalRestApiVersion: '0.1.96',- rpcProxyVersion: '0.1.124',+ rpcProxyVersion: '0.1.125',desktopVersion: '0.10.0',minimumDesktopVersion: '0.1.252',}diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex ae1cfe4e2..affae0926 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.501",+ "version": "0.1.502","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.501",+ "version": "0.1.502","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex 5f434642c..41ab8c29c 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.501",+ "version": "0.1.502","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --git a/mcp-host/src/core/extensions/prePrune.ts b/mcp-host/src/core/extensions/prePrune.tsindex 44676607d..83d4a7047 100644--- a/mcp-host/src/core/extensions/prePrune.ts+++ b/mcp-host/src/core/extensions/prePrune.ts@@ -281,13 +281,13 @@ function findLastUserIndex(messages: ChatMessage[]): number {function parseNativeAttachmentTextPage(content: string-): { page: AttachmentTextPage; wrapperSanitized: string | null } | null {+): { page: AttachmentTextPage; wrapperSanitized: boolean | null } | null {let candidate = content- let wrapperSanitized: string | null = null+ let wrapperSanitized: boolean | null = nullconst wrapped = WRAPPED_ATTACHMENT_OUTPUT_PATTERN.exec(content)if (wrapped) {candidate = wrapped[2]!- wrapperSanitized = wrapped[1]!+ wrapperSanitized = wrapped[1] === 'true'}let parsed: unknowntry {@@ -358,7 +358,7 @@ function isAttachmentTextPage(value: unknown): value is AttachmentTextPage {function buildAttachmentPageStub(parsed: {page: AttachmentTextPage- wrapperSanitized: string | null+ wrapperSanitized: boolean | null}): string {const { page, wrapperSanitized } = parsedconst stub = JSON.stringify({@@ -372,7 +372,9 @@ function buildAttachmentPageStub(parsed: {text: ATTACHMENT_PAGE_COLLAPSE_MARKER,})if (wrapperSanitized === null) return stub- return `<tool_output name="${ATTACHMENT_READ_TOOL_NAME}" sanitized="${wrapperSanitized}">\n${stub}\n</tool_output>`+ // The attribute is rebuilt from the parsed flag, never copied from the input.+ const sanitizedAttribute = wrapperSanitized ? 'true' : 'false'+ return `<tool_output name="${ATTACHMENT_READ_TOOL_NAME}" sanitized="${sanitizedAttribute}">\n${stub}\n</tool_output>`}// ─── Pass 1 — Dedup tool outputs ────────────────────────────────────────────diff --git a/rpc-proxy/package-lock.json b/rpc-proxy/package-lock.jsonindex 9c77755e3..afc66b45e 100644--- a/rpc-proxy/package-lock.json+++ b/rpc-proxy/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-rpc-proxy",- "version": "0.1.124",+ "version": "0.1.125","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-rpc-proxy",- "version": "0.1.124",+ "version": "0.1.125","dependencies": {"@clerum/jwt-key-policy": "file:../packages/jwt-key-policy","cors": "^2.8.5",diff --git a/rpc-proxy/package.json b/rpc-proxy/package.jsonindex b94756662..3357ffac5 100644--- a/rpc-proxy/package.json+++ b/rpc-proxy/package.json@@ -1,6 +1,6 @@{"name": "clerum-rpc-proxy",- "version": "0.1.124",+ "version": "0.1.125","description": "External-facing RPC proxy for tenant-scoped MCP access","main": "dist/main.js","engines": {diff --git a/rpc-proxy/src/__tests__/wake-and-hold-route.test.ts b/rpc-proxy/src/__tests__/wake-and-hold-route.test.tsindex 09dffdda0..cb35bfa87 100644--- a/rpc-proxy/src/__tests__/wake-and-hold-route.test.ts+++ b/rpc-proxy/src/__tests__/wake-and-hold-route.test.ts@@ -1053,3 +1053,99 @@ describe('Host error bodies stay out of rpc-proxy logs', () => {}})})++describe('a hostRef from the URL cannot forge rpc-proxy log lines', () => {+ // Express decodes route params, so `%0D%0A` reaches the route as CR LF.+ const ENCODED_HOST_REF = 'chat%0D%0Allm'++ function captureWarnLines() {+ const spy = vi.spyOn(console, 'warn').mockImplementation(() => {})+ return {+ lines: () => spy.mock.calls.map(args => args.map(String).join(' ')),+ restore: () => spy.mockRestore(),+ }+ }++ // The message route validates hostRef before any log line, so its two+ // failure logs can never receive CR or LF; this pins that refusal.+ it('refuses a CR/LF hostRef on the message route before resolving the Host', async () => {+ const logs = captureWarnLines()+ try {+ const response = await request(makeApp())+ .post(`/rpc/hosts/${ENCODED_HOST_REF}/messages`)+ .set('authorization', 'Bearer token')+ .send({ content: 'hello' })++ // Witness: the hostRef guard answered.+ expect(response.status).toBe(400)+ expect(response.body).toEqual({ error: 'Invalid hostRef' })+ expect(serviceMock.resolveHostConnectionForUser).not.toHaveBeenCalled()+ expect(serviceMock.forwardHostMessageToHost).not.toHaveBeenCalled()+ expect(logs.lines().filter(entry => /[\r\n]/.test(entry))).toEqual([])+ } finally {+ logs.restore()+ }+ })++ it.each([+ {+ site: 'host activity',+ scopes: ['host:activity:read'],+ arrange: () =>+ serviceMock.resolveHostConnectionForUser.mockRejectedValueOnce(new Error('boom')),+ send: (app: express.Express) =>+ request(app)+ .get(`/rpc/hosts/${ENCODED_HOST_REF}/activity`)+ .set('authorization', 'Bearer token'),+ line: '[RPC_PROXY] host activity failed host=chatllm error=',+ },+ {+ site: 'host status',+ scopes: ['host:status:read'],+ arrange: () =>+ serviceMock.resolveHostConnectionForUser.mockRejectedValueOnce(new Error('boom')),+ send: (app: express.Express) =>+ request(app)+ .get(`/rpc/hosts/${ENCODED_HOST_REF}/status`)+ .set('authorization', 'Bearer token'),+ line: '[RPC_PROXY] host status failed host=chatllm error=',+ },+ {+ site: 'host status malformed',+ scopes: ['host:status:read'],+ arrange: () => serviceMock.forwardHostStatus.mockResolvedValueOnce(null),+ send: (app: express.Express) =>+ request(app)+ .get(`/rpc/hosts/${ENCODED_HOST_REF}/status`)+ .set('authorization', 'Bearer token'),+ line: '[RPC_PROXY] host status malformed host=chatllm user=',+ },+ {+ site: 'host health',+ scopes: ['host:health:read'],+ arrange: () =>+ serviceMock.resolveHostConnectionForUser.mockRejectedValueOnce(new Error('boom')),+ send: (app: express.Express) =>+ request(app)+ .get(`/rpc/hosts/${ENCODED_HOST_REF}/health`)+ .set('authorization', 'Bearer token'),+ line: '[RPC_PROXY] host health failed host=chatllm error=',+ },+ ])(+ 'strips CR and LF from the hostRef in the $site log line',+ async ({ scopes, arrange, send, line }) => {+ authTokenMock.verifyRpcToken.mockReturnValue({ ...VALID_CLAIMS, scopes })+ arrange()+ const logs = captureWarnLines()+ try {+ await send(makeApp())++ // Witness: the route reached the log site and wrote exactly one line for it.+ expect(logs.lines().filter(entry => entry.includes(line))).toHaveLength(1)+ expect(logs.lines().filter(entry => /[\r\n]/.test(entry))).toEqual([])+ } finally {+ logs.restore()+ }+ }+ )+})diff --git a/rpc-proxy/src/routes/rpc.ts b/rpc-proxy/src/routes/rpc.tsindex ebc4389a1..9c2907c7b 100644--- a/rpc-proxy/src/routes/rpc.ts+++ b/rpc-proxy/src/routes/rpc.ts@@ -44,6 +44,7 @@ import {isUpstreamTimeoutError,isWakeEligibleHostError,respondWithWakeAndHold,+ sanitizeHostRefForLog,} from '../services/wakeAndHold.js'import { mintOrReuseDirectTraceContext } from '../traceContext.js'@@ -523,7 +524,7 @@ export function createRpcRouter(): Router {})} catch (error) {console.warn(- `[RPC_PROXY] host message forward failed host=${hostRef} error=${describeErrorForLog(+ `[RPC_PROXY] host message forward failed host=${sanitizeHostRefForLog(hostRef)} error=${describeErrorForLog(error)}`)@@ -567,7 +568,7 @@ export function createRpcRouter(): Router {return}console.warn(- `[RPC_PROXY] host message forward failed host=${String(req.params.hostRef || '').trim()} error=${describeErrorForLog(+ `[RPC_PROXY] host message forward failed host=${sanitizeHostRefForLog(String(req.params.hostRef || '').trim())} error=${describeErrorForLog(error)}`)@@ -1667,7 +1668,7 @@ export function createRpcRouter(): Router {res.status(200).json(activity)} catch (error) {console.warn(- `[RPC_PROXY] host activity failed host=${String(req.params.hostRef || '').trim()} error=${describeErrorForLog(+ `[RPC_PROXY] host activity failed host=${sanitizeHostRefForLog(String(req.params.hostRef || '').trim())} error=${describeErrorForLog(error)}`)@@ -1701,14 +1702,16 @@ export function createRpcRouter(): Router {const status = await forwardHostStatus(host)if (!status) {- console.warn(`[RPC_PROXY] host status malformed host=${hostRef} user=${auth.sub}`)+ console.warn(+ `[RPC_PROXY] host status malformed host=${sanitizeHostRefForLog(hostRef)} user=${auth.sub}`+ )res.status(502).json({ error: 'Invalid upstream host status response' })return}res.status(200).json(status)} catch (error) {console.warn(- `[RPC_PROXY] host status failed host=${String(req.params.hostRef || '').trim()} error=${describeErrorForLog(+ `[RPC_PROXY] host status failed host=${sanitizeHostRefForLog(String(req.params.hostRef || '').trim())} error=${describeErrorForLog(error)}`)@@ -1744,7 +1747,7 @@ export function createRpcRouter(): Router {res.status(200).json(health)} catch (error) {console.warn(- `[RPC_PROXY] host health failed host=${String(req.params.hostRef || '').trim()} error=${describeErrorForLog(+ `[RPC_PROXY] host health failed host=${sanitizeHostRefForLog(String(req.params.hostRef || '').trim())} error=${describeErrorForLog(error)}`)diff --git a/rpc-proxy/src/services/wakeAndHold.ts b/rpc-proxy/src/services/wakeAndHold.tsindex a8f3c07b9..aaa8786f8 100644--- a/rpc-proxy/src/services/wakeAndHold.ts+++ b/rpc-proxy/src/services/wakeAndHold.ts@@ -5,7 +5,7 @@ import { type HostWakeApiResponse, requestHostWakeFromControlApi } from './contrimport { forwardHostHealth } from './mcpHostRestService.js'/** Strip control characters and newlines from user-derived hostRef before log interpolation. */-function sanitizeHostRefForLog(hostRef: string): string {+export function sanitizeHostRefForLog(hostRef: string): string {return hostRef.replace(/[\r\n\t\x00-\x1f\x7f]/g, '')}