security(mcp): tool poisoning detection and per-tool trust metadata (#2459, #2420)#2472
Merged
security(mcp): tool poisoning detection and per-tool trust metadata (#2459, #2420)#2472
Conversation
…ta (#2459, #2420) Implement multi-layered MCP client-side defenses against tool poisoning (arXiv:2603.22489) and per-tool capability/sensitivity metadata for data-flow policy enforcement (arXiv:2601.08012). - sanitize_tools() now returns SanitizeResult with injection_count, flagged_tools, and flagged_patterns (pattern name per matched field) - 16 injection patterns in INJECTION_PATTERNS (role override, jailbreak, delimiter escape, base64 payload, exfil via image/link, etc.) - Unicode hardening: strip Cf-category format chars before pattern scan - apply_injection_penalties(): applies trust score penalties (capped at MAX_INJECTION_PENALTIES_PER_REGISTRATION=3) and auto-demotes server trust level when recommended level is more restrictive; never promotes - ToolSecurityMeta on McpTool: DataSensitivity (None/Low/Medium/High) and CapabilityClass set (FilesystemRead/Write, Network, Shell, DatabaseRead, MemoryWrite, ExternalApi) - infer_security_meta(): keyword-based heuristic classifier; explicit filesystem keywords only, generic verbs excluded; defaults to Low - Operator config override via mcp.servers[].tool_metadata TOML section - check_data_flow(): blocks High-sensitivity tools on Untrusted/Sandboxed servers at registration time; Medium on Sandboxed emits warning - sanitize_string delegates to sanitize_string_tracked (DRY) Closes #2459, closes #2420
This was referenced Mar 30, 2026
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
sanitize_tools()returnsSanitizeResultwith injection count, flagged tools, and flagged pattern namesapply_injection_penalties(): trust score penalties capped at 3 per registration batch, auto-demotes server trust level (never promotes)ToolSecurityMetaonMcpTool:DataSensitivity(None/Low/Medium/High) +CapabilityClassset (FilesystemRead/Write, Network, Shell, DatabaseRead, MemoryWrite, ExternalApi)infer_security_meta()keyword heuristic with explicit filesystem keywords only; defaults unknown tools toDataSensitivity::Lowmcp.servers[].tool_metadataTOML sectioncheck_data_flow()blocks High-sensitivity tools on Untrusted/Sandboxed servers at registration timeTest plan
cargo nextest run --workspace --lib --bins)cargo +nightly fmt --checkcleancargo clippy --workspace -- -D warningscleanapply_injection_penalties(8 direct: zero/1/cap-at-3/cap-at-10/no-store/demotion),infer_security_meta(all keyword categories + false-positive guards),check_data_flow(all DataSensitivity x McpTrustLevel combinations),SanitizeResultpopulationCloses #2459
Closes #2420