Skip to content

fix(server): reject NaN/Infinity in legacy HTTP, stdio and SSE transports - #3972

Draft
mia03ther wants to merge 1 commit into
modelcontextprotocol:mainfrom
mia03ther:fix/3965-nan-infinity-legacy
Draft

mia03ther wants to merge 1 commit into
modelcontextprotocol:mainfrom
mia03ther:fix/3965-nan-infinity-legacy

Conversation

@mia03ther

Copy link
Copy Markdown

Fixes #3965.

Legacy Streamable HTTP, stdio and SSE parsed inbound JSON with pydantic-core's default allow_inf_nan=True, so a tool call whose arguments contained the non-standard literals NaN, Infinity or -Infinity reached the tool handler as non-finite Python floats instead of being rejected as a parse error.

Parse with allow_inf_nan=False at the three server entry points so the literals take the existing parse-error path: HTTP 400 with -32700 for legacy Streamable HTTP, and an in-stream exception (the same contract as malformed JSON today) for stdio and SSE. The shared jsonrpc_message_adapter is untouched, so client-side parsing is unchanged.

Adds regression tests in tests/server/test_sse_security.py, tests/server/test_stdio.py and tests/server/test_streamable_http_manager.py, parameterized over NaN, Infinity and -Infinity.

…orts

Legacy Streamable HTTP, stdio and SSE parsed inbound JSON with
pydantic-core's default allow_inf_nan=True, so a tools/call whose
arguments contained the non-standard literals NaN, Infinity or
-Infinity reached the tool handler as non-finite Python floats
instead of being rejected as a parse error.

Parse with allow_inf_nan=False at the three server entry points so
the literals take the existing parse-error path: HTTP 400 with
-32700 for legacy Streamable HTTP, and an in-stream exception (the
same contract as malformed JSON today) for stdio and SSE. The
shared jsonrpc_message_adapter is untouched, so client-side parsing
is unchanged.

Fixes modelcontextprotocol#3965

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.

Legacy Streamable HTTP and stdio pass NaN/Infinity from request JSON into tool handlers

1 participant