Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(mcp-host): catch a secret a link splits, or one holding a quote, before attaching a document
marcoteb69152471f7e6
diff --git a/mcp-host/src/core/tools/__tests__/generatedArtifactAttachments.test.ts b/mcp-host/src/core/tools/__tests__/generatedArtifactAttachments.test.tsindex 4b3154bb8..06e43f2bc 100644--- a/mcp-host/src/core/tools/__tests__/generatedArtifactAttachments.test.ts+++ b/mcp-host/src/core/tools/__tests__/generatedArtifactAttachments.test.ts@@ -255,6 +255,9 @@ describe('generated internal artifact attachments', () => {['a character reference', 'probe-redaction-value'],['a zero-width space', 'probe-redaction\u200B-value'],['markdown emphasis', 'probe-**redaction**-value'],+ ['a markdown link', 'probe-[redaction](https://a.example)-value'],+ ['a markdown link holding a reference', 'probe-[redaction](https://a.example)-value'],+ ['an image', 'probe--value'],])('does not attach a PDF that prints a secret split by %s', async (_label, body) => {process.env.CLERUM_OUTPUT_DIR = outputDirconst registry = new NativeToolRegistry(@@ -286,6 +289,70 @@ describe('generated internal artifact attachments', () => {expect(safe.attachments ?? []).toHaveLength(1)})+ it('does not attach a document whose arguments hold a secret with a quote or a backslash', async () => {+ process.env.CLERUM_OUTPUT_DIR = outputDir+ const secret = 'probe"redac\\tion-value'+ const registry = new NativeToolRegistry(+ {+ workspacePath: outputDir,+ shellTimeout: 5000,+ toolTimeout: 60000,+ toolProgressInterval: 30000,+ httpAllowlist: [],+ envAllowlist: ['PATH'],+ memoryMaxSize: 1048576,+ },+ 'conv-1',+ undefined,+ undefined,+ undefined,+ undefined,+ null,+ {+ maxBytes: 52_428_800,+ secretEntriesProvider: () => [{ name: 'PROBE_VALUE', value: secret }],+ }+ )+ const pdf = registry.get('clerum__generate_pdf')!+ const leaked = await pdf.execute({ filename: 'quoted.pdf', body: `value: ${secret}` })+ expect(leaked.is_error).toBe(false)+ expect(leaked.attachments ?? []).toHaveLength(0)+ })++ it('does not attach a DOCX whose table cell prints a secret a link splits', async () => {+ process.env.CLERUM_OUTPUT_DIR = outputDir+ const registry = new NativeToolRegistry(+ {+ workspacePath: outputDir,+ shellTimeout: 5000,+ toolTimeout: 60000,+ toolProgressInterval: 30000,+ httpAllowlist: [],+ envAllowlist: ['PATH'],+ memoryMaxSize: 1048576,+ },+ 'conv-1',+ undefined,+ undefined,+ undefined,+ undefined,+ null,+ {+ maxBytes: 52_428_800,+ secretEntriesProvider: () => [{ name: 'PROBE_VALUE', value: 'probe-redaction-value' }],+ }+ )+ const docx = registry.get('clerum__generate_docx')!+ const cell = 'probe-[redaction](https://a.example)-value'+ const leaked = await docx.execute({+ filename: 'split.docx',+ body: 'Table:',+ tables: [{ headers: ['Value'], rows: [[cell]] }],+ })+ expect(leaked.is_error).toBe(false)+ expect(leaked.attachments ?? []).toHaveLength(0)+ })+it('native internal tools return generated artifact attachments through the adapter', async () => {const config: NativeToolConfig = {workspacePath: outputDir,diff --git a/mcp-host/src/core/tools/generatedArtifactAttachments.ts b/mcp-host/src/core/tools/generatedArtifactAttachments.tsindex 028439a82..36017c956 100644--- a/mcp-host/src/core/tools/generatedArtifactAttachments.ts+++ b/mcp-host/src/core/tools/generatedArtifactAttachments.ts@@ -104,17 +104,34 @@ function textContainsRedactableSecretEntry(})}+/**+ * Every string, number and key in `value` as written. A serialized form+ * escapes quotes and backslashes, so a secret holding either would not match it.+ */+function payloadTexts(value: unknown, out: string[], seen: Set<object>, depth: number): void {+ if (typeof value === 'string') out.push(value)+ else if (typeof value === 'number' || typeof value === 'bigint') out.push(String(value))+ else if (value && typeof value === 'object' && depth <= 64 && !seen.has(value)) {+ seen.add(value)+ if (Array.isArray(value)) {+ for (const item of value) payloadTexts(item, out, seen, depth + 1)+ } else {+ for (const [key, item] of Object.entries(value)) {+ out.push(key)+ payloadTexts(item, out, seen, depth + 1)+ }+ }+ }+}+function sourcePayloadContainsRedactableSecretEntry(sourcePayload: unknown,entries: ArtifactSecretEntry[]): boolean {if (sourcePayload === undefined || entries.length === 0) return false- try {- const serialized = JSON.stringify(sourcePayload)- return textContainsRedactableSecretEntry(serialized ?? '', entries)- } catch {- return textContainsRedactableSecretEntry(String(sourcePayload), entries)- }+ const texts: string[] = []+ payloadTexts(sourcePayload, texts, new Set(), 0)+ return texts.some(text => textContainsRedactableSecretEntry(text, entries))}export function isInternalGeneratedArtifactSourceTool(sourceTool: string | undefined): boolean {diff --git a/mcp-host/src/workflow/toolText.ts b/mcp-host/src/workflow/toolText.tsindex 6457eebbe..4947aafc8 100644--- a/mcp-host/src/workflow/toolText.ts+++ b/mcp-host/src/workflow/toolText.ts@@ -6,7 +6,7 @@* boxes, and the markdown parsers split on '\n' only. Cleaning the arguments* once, before a generator reads them, covers every string that can reach a file.*/-import { htmlToPlainText } from './inlineMarkup'+import { htmlToPlainText, inlineSpans } from './inlineMarkup'/*** CSI and terminated OSC sequences, then any other escape with its@@ -75,8 +75,9 @@ const MARKDOWN_ESCAPE = /\\([!-/:-@[-`{-~])/g* The text of every string in `args` in the forms a document generator may* print it: as sent, cleaned as cleanToolArgs cleans it, with HTML tags,* character references, backslash escapes and invisible characters taken out,- * and with markdown markers taken out too. Text split by any of these prints- * whole, so a check for leaked secrets that reads every form sees it whole.+ * with markdown markers taken out too, and read as inline markdown, where a+ * link prints its label. Text split by any of these prints whole, so a check+ * for leaked secrets that reads every form sees it whole.*/export function printedForms(args: unknown): string[] {const sent: string[] = []@@ -92,5 +93,13 @@ export function printedForms(args: unknown): string[] {htmlToPlainText(text).replace(MARKDOWN_ESCAPE, '$1').replace(INVISIBLE, ''))const bare = printed.map(text => text.replace(/[*_~`]/g, ''))- return [...sent, ...cleaned, ...printed, ...bare]+ // As the PDF and DOCX generators read inline text, where a link or an image+ // prints only its label, so text one splits is seen whole.+ const spoken = cleaned.map(text =>+ inlineSpans(text)+ .map(span => span.text)+ .join('')+ .replace(INVISIBLE, '')+ )+ return [...sent, ...cleaned, ...printed, ...bare, ...spoken]}