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

Aberta
#1,343 1 comentário 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
72/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
java, json

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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
Linguagem predominante
Java
Estrelas
3.8k
Forks
1.1k
Merge médio
1d 3h
PRs com merge (30d)
38

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de modelcontextprotocol/java-sdk

Todas as issues de modelcontextprotocol/java-sdk

Issues semelhantes

Mais issues de Java

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.