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

Ouverte
#1,343 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
72/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
java, json

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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
Langage dominant
Java
Étoiles
3.8k
Forks
1.1k
Merge moyen
1 j 3 h
PR mergées (30 j)
38

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de modelcontextprotocol/java-sdk

Toutes les issues de modelcontextprotocol/java-sdk

Issues similaires

Plus d'issues Java

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.