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

Đang mở
#1,343 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java, json

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
Java
Star
3.8k
Fork
1.1k
Merge trung bình
1 ngày 3 giờ
Pull request đã merge (30 ngày)
38

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của modelcontextprotocol/java-sdk

Tất cả issue của modelcontextprotocol/java-sdk

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.