Skip to content

Reject non-standard JSON constants in modern HTTP - #3967

Open
lzcdev wants to merge 1 commit into
modelcontextprotocol:mainfrom
lzcdev:fix/strict-json-constants
Open

lzcdev wants to merge 1 commit into
modelcontextprotocol:mainfrom
lzcdev:fix/strict-json-constants

Conversation

@lzcdev

@lzcdev lzcdev commented Dec 3, 2026

Copy link
Copy Markdown

Fixes #3961.

json.loads() in the modern Streamable HTTP entry accepts NaN, Infinity and -Infinity by default. Those literals are outside RFC 8259 and reached tool handlers as Python floats, returning HTTP 200.

Fix

  • Parse with a parse_constant hook that raises ValueError, routing non-standard constants through the existing PARSE_ERROR path before dispatch.
  • Valid JSON parsing is unchanged.

Tests

  • Regression test parametrized over NaN, Infinity, and -Infinity: asserts HTTP 400 with code -32700 and that the tool handler is not invoked.
  • Before the fix: all 3 new cases returned 200 and called the handler.
  • After the fix: 4 targeted tests pass (the 3 new cases plus the existing malformed-body test).
  • ruff check, ruff format --check, and pyright are clean.
  • Full suite: 6235 passed, 9 skipped, 1 xfailed. Locally the blockbuster guard had to be disabled because the sandbox shim triggers a false-positive BlockingError; the guard is untouched in this diff.

Signed-off-by: lzcdev 16014249+lzcdev@users.noreply.github.com

json.loads() accepts NaN, Infinity and -Infinity by default, which are
outside RFC 8259. The modern Streamable HTTP entry passed those values
straight to tool handlers. Parse with a parse_constant hook that raises
ValueError so the existing PARSE_ERROR path rejects the request before
dispatch.

Fixes modelcontextprotocol#3961

Signed-off-by: lzcdev <16014249+lzcdev@users.noreply.github.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Modern Streamable HTTP passes NaN/Infinity from request JSON into tool handlers

1 participant