DefaultJsonSchemaValidator: caching by $id alone can validate tool input against another tool's schema
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 72/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- java, json
研究方向
Read generateCacheKey() in mcp-json-jackson2/src/main/java/io/modelcontextprotocol/json/schema/jackson2/DefaultJsonSchemaValidator.java and its Jackson 3 counterpart. First inspect how each validator builds and uses its cache key, then reproduce the issue with two schemas sharing $id but having different properties or required fields. Done means both modules distinguish different schema documents and validation behaves correctly for each; the issue does not name test files.
由索引模型根據 Issue 內容生成。
描述
Summary
DefaultJsonSchemaValidator uses the optional JSON Schema $id field as the sole cache key when present. Unlike the hashCode() collision case (#1328), two different schema documents that share the same $id URI will share one compiled Schema instance. Tool B's tools/call arguments may then be validated against Tool A's schema.
Affected code
mcp-json-jackson2/src/main/java/io/modelcontextprotocol/json/schema/jackson2/DefaultJsonSchemaValidator.java—generateCacheKey()mcp-json-jackson3/src/main/java/io/modelcontextprotocol/json/schema/jackson3/DefaultJsonSchemaValidator.java—generateCacheKey()
When $id is present, the cache key is String.valueOf(schema.get("$id")) with no hash of the schema body.
Steps to reproduce
- Register two tools on an MCP server (or unit-test the validator directly) with identical
$idbut differentproperties/requiredininputSchema. - Call
validate(toolB.inputSchema(), argumentsValidForBButInvalidForA). - Observe validation outcome depends on which schema was compiled and cached first.
Expected behavior
Cache keys must uniquely identify the full schema document (content-based hash, canonical JSON, or composite key $id + content hash). Different documents must never share a compiled schema even if $id matches.
Actual behavior
First registered/compiled schema wins for that $id; later tools with the same $id may get wrong validation.
Impact
Incorrect accept/reject of tool arguments; security-relevant when validation is used as a gate before handler execution.
Related
- #1328 —
hashCode()fallback cache key collision (orthogonal but same component)
Environment
- Modules:
mcp-json-jackson2,mcp-json-jackson3 - Logic present on current
main/ 2.2.x line
- 主要語言
- Java
- 星號
- 3.8k
- 分支
- 1.1k
- 平均合併
- 1 天 3 小時
- 30 天內合併 PR
- 38
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
modelcontextprotocol/java-sdk 的其他 Issue
-
Modern `HttpServletMcpTransport` does not check `Mcp-Name` when `params.name` or `params.uri` is not a JSON string可能已有人在做 @starryeye 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 75/100
modelcontextprotocol/java-sdk#1352 · 1 則留言 ·
維護者通常 1 天內回覆
-
Unknown tool error always says "Unknown tool: invalid_tool_name" instead of the name that was called未關閉
難度 1/5 1 小時以內 新手友好度 85/100
modelcontextprotocol/java-sdk#1346 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 64/100
modelcontextprotocol/java-sdk#1345 · 1 則留言 ·
維護者通常 1 天內回覆
-
area/server legacy P3
難度 2/5 1-3 小時 新手友好度 72/100
modelcontextprotocol/java-sdk#1330 · 1 則留言 ·
維護者通常 1 天內回覆
-
Client request handlers that complete empty send no JSON-RPC response可能已有人在做 @1fanwang 於 83 天前認領。 未關閉area/client bug P2
難度 2/5 1-3 小時 新手友好度 84/100
modelcontextprotocol/java-sdk#1124 · 6 則留言 ·
維護者通常 1 天內回覆
查看 modelcontextprotocol/java-sdk 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 65/100
-
crash
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
-
難度 2/5 1-3 小時 新手友好度 74/100
-
account bug course exam iris lecture
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆