DefaultJsonSchemaValidator: caching by $id alone can validate tool input against another tool's schema

未關閉
#1,343 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 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

  1. Register two tools on an MCP server (or unit-test the validator directly) with identical $id but different properties / required in inputSchema.
  2. Call validate(toolB.inputSchema(), argumentsValidForBButInvalidForA).
  3. 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

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

modelcontextprotocol/java-sdk 的其他 Issue

查看 modelcontextprotocol/java-sdk 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。