Skip to content

Commit 64d4e3e

Browse files
authored
fix: remove malicious characters from MCP tool description (aws#1977)
1 parent ed8b4f6 commit 64d4e3e

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/mcp/mcpManager.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ import {
1818
MCPServerPermission,
1919
AgentConfig,
2020
} from './mcpTypes'
21-
import { isEmptyEnv, loadAgentConfig, saveAgentConfig, sanitizeName, getGlobalAgentConfigPath } from './mcpUtils'
21+
import {
22+
isEmptyEnv,
23+
loadAgentConfig,
24+
saveAgentConfig,
25+
sanitizeName,
26+
getGlobalAgentConfigPath,
27+
sanitizeContent,
28+
} from './mcpUtils'
2229
import { AgenticChatError } from '../../errors'
2330
import { EventEmitter } from 'events'
2431
import { Mutex } from 'async-mutex'
@@ -340,7 +347,7 @@ export class McpManager {
340347
this.mcpTools.push({
341348
serverName,
342349
toolName: t.name,
343-
description: t.description ?? '',
350+
description: sanitizeContent(t.description ?? ''),
344351
inputSchema: t.inputSchema ?? {},
345352
})
346353
}

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/mcp/mcpUtils.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
enabledMCP,
2121
normalizePathFromUri,
2222
saveAgentConfig,
23+
sanitizeContent,
2324
} from './mcpUtils'
2425
import type { MCPServerConfig } from './mcpTypes'
2526
import { pathToFileURL } from 'url'
@@ -584,3 +585,11 @@ describe('normalizePathFromUri', () => {
584585
expect(result).to.equal(invalidUri)
585586
})
586587
})
588+
589+
describe('sanitizeContent', () => {
590+
it('removes Unicode Tag characters (U+E0000–U+E007F)', () => {
591+
const input = 'foo\u{E0001}bar\u{E0060}baz'
592+
const expected = 'foobarbaz'
593+
expect(sanitizeContent(input)).to.equal(expected)
594+
})
595+
})

server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/mcp/mcpUtils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,3 +1009,8 @@ export function createNamespacedToolName(
10091009
duplicateNum++
10101010
}
10111011
}
1012+
1013+
export function sanitizeContent(input: string): string {
1014+
// Remove any Unicode Tag characters (U+E0000–U+E007F)
1015+
return input.replace(/[\u{E0000}-\u{E007F}]/gu, '')
1016+
}

0 commit comments

Comments
 (0)