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

オープン
#1,343 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
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時間
マージ済み PR(30日)
38

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

modelcontextprotocol/java-sdk のほかの issue

modelcontextprotocol/java-sdk の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。