Conversation
…ool-poisoning injection (#1691) Malicious MCP servers can embed prompt injection payloads in tool `description` and `inputSchema` fields. These bypass ContentSanitizer because they arrive as trusted system content (tool catalog), not as user or web content. New `crates/zeph-mcp/src/sanitize` module: - 17 injection-detection regexes compiled once via LazyLock (system-prompt override, role injection, jailbreak, data exfiltration, URL execution, XML/HTML tag escape, base64 blobs, shell commands, delimiter escapes) - Unicode Cf-category strip pass before regex matching to defeat zero-width and format-character bypass attempts - Whole-field replacement with "[sanitized]" on any pattern match - Structured WARN log on detection (server_id, tool_name, field, matched text) - `sanitize_tool_name`: restricts to [a-zA-Z0-9_-], fallback "_unnamed" - `sanitize_server_id`: restricts to [a-zA-Z0-9_.-], fallback "_unnamed" - Recursive JSON schema walker sanitizes ALL string values (title, enum, default, examples, const, description), depth-capped at 10 - Descriptions capped at 1024 bytes (char boundary safe) Hook: `sanitize_tools()` called in `McpManager::connect_all()` and `add_server()` immediately after `list_tools()` returns. Tool registration is never blocked — only text is cleaned. +23 unit tests (zeph-mcp: 189 → 212).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1691.
Malicious MCP servers can embed prompt injection payloads in tool
descriptionandinputSchemafields. These bypassContentSanitizerbecause they arrive as trusted system content (tool catalog), not as user or web content.New
crates/zeph-mcp/src/sanitizemodule applies sanitization at registration time before any tool definition reaches the LLM context:(?i)case-insensitive matching"[sanitized]"on any match — no surgical replacements that preserve surrounding attacker-controlled textsanitize_tool_name: restricts to[a-zA-Z0-9_-], max 64 chars, fallback"_unnamed"— prevents XML attribute injection in prompt.rssanitize_server_id: restricts to[a-zA-Z0-9_.-], max 128 chars, fallback"_unnamed"— same defense for server_id XML interpolationtitle,enum,default,examples,const,description), depth-capped at 10Hook:
sanitize_tools()called in bothMcpManager::connect_all()andadd_server()immediately afterlist_tools()returns. Tool registration is never blocked — only text is cleaned.Test plan
cargo nextest run -p zeph-mcp --features full— 212 tests, all pass (+23 new)cargo clippy --workspace --features full -- -D warnings— 0 warningscargo +nightly fmt --check— cleanFollow-up issues
zeph-mcpandzeph-coresanitizers (extract to shared module)tools/list_changedMCP notification path — refreshed tools bypass sanitization