Skip to content

fix: refuse lone surrogates in MCP arguments, auth bodies, seeds and fixtures (#1016) - #1022

Merged
jimhoyd merged 2 commits into
mainfrom
claude/surrogates-mcp-auth-1016
Sep 30, 2026
Merged

jimhoyd merged 2 commits into
mainfrom
claude/surrogates-mcp-auth-1016

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1016

#996 refused an unpaired UTF-16 surrogate only on paths through core's readBody. This covers the other JSON inputs that reach a handler or stored data.

MCP

  • Extension (packages/mcp): a tools/call or prompts/get argument holding a lone surrogate, as a value at any depth or as a key, is refused before the schema check. The answer is -32602 Invalid params, the message names the argument, and data is {argument, code: "invalid_unicode"}. The handler never runs.
  • urlcode mcp (core, stdio): same -32602, checked before any tool runs, so an authoring tool never writes U+FFFD to a file.
  • The shared check is a new illFormedMember in body-validation.ts. It and holdsIllFormedString are exported from @jimhoyd/urlcode/body-schema.

Auth

  • The mount never called readBody. It passed the raw bytes to Better Auth, which parses its own body, keeps the lone surrogate and lets SQLite store it as U+FFFD. Now every non-empty body on a served path goes through readBody first, and a refusal answers core's status as {"error": <code>} (400 invalid_unicode, and also duplicate_key, too_deep, invalid_encoding, invalid_json, 415 unsupported_media_type). Better Auth already accepts only application/json. It still parses the unchanged bytes.
  • urlcode-auth create-user refuses such input with exit 2.

Other entry points

Docs
docs/EXTENSIONS.md (readBody row, new body-schema helpers), docs/TOOLING.md (MCP), docs/READINESS.md (seed and fixture), docs/RUNTIME-IMPLEMENTATION.md (RIM-EXT-HTTP-001), SECURITY.md, auth README/SECURITY/CHANGELOG, mcp README/SECURITY/llms.txt/CHANGELOG, regenerated llms-full.txt.

Evidence

  • New tests:
    • packages/mcp/test/mcp.test.ts: value, nested, key and prompt refusals; a surrogate pair is admitted.
    • test/mcp.test.ts.
    • packages/auth/test/auth.test.ts: sign-up/sign-in refusal with no account and no cookie, 415, a surrogate pair still signs up, create-user.
    • test/hermetic-host.test.ts (seed) and test/authoring-errors.test.ts (fixture).
  • npm run verify and npm run test:package pass locally on Node 26 (core packs at 1063194 bytes, within budget).
  • This is about data consistency, not a security review.

🤖 Generated with Claude Code

…fixtures (#1016)

#996 refused an unpaired UTF-16 surrogate only on paths through core's JSON
body reader. The remaining JSON inputs that reach stored data or a handler
now refuse one too:

- MCP extension: a tools/call or prompts/get argument holding one is -32602
  naming the argument, data {argument, code: "invalid_unicode"}; the handler
  never runs. The SDK parses the body itself, so readBody never saw it.
- urlcode mcp (core, stdio): the same -32602 before any tool runs.
- auth mount: every request body passes core's readBody before Better Auth
  parses it (Better Auth stored the surrogate as U+FFFD), answering its
  status and {"error": code}. urlcode-auth create-user refuses one (exit 2).
- tests/seed.json entries (invalid-seed) and tests/requests.json
  (invalid-fixture), which a database or a UTF-8 request would turn into
  U+FFFD.

core's body-schema subpath exports holdsIllFormedString and illFormedMember
for JSON a library parses where readBody cannot run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jimhoyd
jimhoyd enabled auto-merge (squash) September 30, 2026 00:38
@jimhoyd
jimhoyd merged commit c1ecc24 into main Sep 30, 2026
24 checks passed
@jimhoyd
jimhoyd deleted the claude/surrogates-mcp-auth-1016 branch September 30, 2026 00:45
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.

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

1 participant