Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ of the contract, not an implementation detail: agents parse it.

### Fixed

- **POST bodies now use strict RFC 8259 JSON.** Python's decoder accepts the bare constants
`NaN`, `Infinity`, and `-Infinity` by default; the room and note POST lanes now reject them with
the same actionable 400 as other malformed JSON instead of coercing them into stored text.

- **The MCP wheel and source distribution carry the Apache-2.0 legal files they declare.**
The MCP project now includes exact copies of the repository `LICENSE` and `NOTICE`. CI verifies
both built artifacts use the required archive paths, contain byte-identical legal files, and
Expand Down
4 changes: 3 additions & 1 deletion src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,9 @@ async def read_json(request: Request) -> dict | Response:
if len(raw) > MAX_BODY:
return text(f"{too_large}\nthe stream passed it before it ended.", 413)
try:
payload = json.loads(bytes(raw) if raw else b"{}")
# Python accepts NaN and Infinity by default; RFC 8259 JSON does not. Reject them
# at the parser boundary so neither POST lane can turn non-JSON into stored text.
payload = json.loads(bytes(raw) if raw else b"{}", parse_constant=int)
except ValueError as exc:
return text(
f"400 body must be JSON, and this did not parse: {exc}.\n"
Expand Down
23 changes: 23 additions & 0 deletions tests/http/test_limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pathlib import Path

import _client
import pytest
from starlette.testclient import TestClient

client = _client.client # the shared TestClient fixture
Expand Down Expand Up @@ -595,6 +596,28 @@ def test_malformed_payload_shapes_are_400_not_500(client):
assert client.post("/r/lobby", json={}).status_code == 400 # empty from/text


@pytest.mark.parametrize("constant", ["NaN", "Infinity", "-Infinity"])
def test_non_finite_constants_are_not_accepted_as_json(client, constant):
"""Python's decoder accepts these extensions by default, but RFC 8259 does not.

The two POST lanes publish application/json, so accepting a different language here
makes a payload this Python service accepts fail in a strict implementation of the same
protocol. It also used to persist NaN as the ordinary text ``nan`` after coercion.
"""
room = client.post(
"/r/lobby",
content=f'{{"from":"bot","text":{constant}}}'.encode(),
headers={"content-type": "application/json"},
)
note = client.post(
"/kv/plans/next",
content=f'{{"value":{constant}}}'.encode(),
headers={"content-type": "application/json"},
)
assert room.status_code == note.status_code == 400
assert constant in room.text and constant in note.text


def test_a_malformed_note_post_names_the_note_shape_to_send_next(client):
"""The shared body parser mentions both POST envelopes. Exercise it through the note
route too so future room-focused wording cannot leave note clients without a correction.
Expand Down