Skip to content

[Bug]: Lone surrogates are not refused in MCP tool arguments or auth sign-up bodies (only core readBody paths refuse them) #1016

Closed

Description

@jimhoyd

Runtime revision and environment

main at 21b4dfd (includes #996, "refuse lone surrogates at every JSON boundary"). Node 24, macOS.

Minimal reproduction

#996 made core's readBody refuse a lone UTF-16 surrogate with 400 invalid_unicode. Two JSON entry points do not go through readBody, so a lone surrogate is not refused there:

  1. MCP tool arguments (packages/mcp). Send this body to a tool's endpoint:
    {"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"echo","arguments":{"message":"\ud800x"}}}
    The answer is 200, and the handler receives the lone surrogate: it reported {"wellFormed":false,"codeUnit":"d800"}. packages/mcp/src/mcp.ts (around lines 521-523) hands the body to the SDK's own parser, and the tool input schema check has no unicode rule. StoreExports create/update still refuse such a value (422). The exception is when the value is used as a principal id: see [Bug]: Store: a transition's stamp: actor stores an unvalidated principal id from StoreExports/host transactions (lone surrogate, over maxLength), then reads 503 and restart is refused #1015.
  2. Auth sign-up (signUp: true). POST /api/auth/sign-up/email with "name":"\ud800Bob" answers 200. The stored name is EFBFBD 42 6F 62 (U+FFFD followed by "Bob"): silently replaced rather than refused. Better Auth parses its own body.

Expected: either both are refused like core's body reader, or the docs name the boundaries the refusal covers (core's body reader, the store) and say that MCP arguments and Better Auth bodies are not among them.

Relevant output

200 data: {"result":{"content":[{"type":"text","text":"{\"wellFormed\":false,\"codeUnit\":\"d800\"}"}] …
sign-up status 200 … "name":"�Bob"
stored name hex EFBFBD426F62 wellFormed true

Neither case lets a caller store a lone surrogate in the store. This is about consistency and docs, not security.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions