Repository navigation
fix: refuse lone surrogates in MCP arguments, auth bodies, seeds and fixtures (#1016) - #1022
Merged
Merged
Conversation
…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
enabled auto-merge (squash)
September 30, 2026 00:38
…regenerate references Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
packages/mcp): atools/callorprompts/getargument 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, anddatais{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.illFormedMemberinbody-validation.ts. It andholdsIllFormedStringare exported from@jimhoyd/urlcode/body-schema.Auth
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 throughreadBodyfirst, and a refusal answers core's status as{"error": <code>}(400 invalid_unicode, and alsoduplicate_key,too_deep,invalid_encoding,invalid_json,415 unsupported_media_type). Better Auth already accepts onlyapplication/json. It still parses the unchanged bytes.urlcode-auth create-userrefuses such input with exit 2.Other entry points
tests/seed.json: refused in core's seed preparation (invalid-seed), whichever way the seed arrives. Seeds are written to databases.tests/requests.json: refused (invalid-fixture). A request sends text as UTF-8, so the case silently sent U+FFFD. The error says how to send the escape itself.urlcode.yamland interchange import. The YAML parser accepts"\ud800". This is project config, not a request boundary.urlcode-auditstdin. Nothing known is stored from them.-32602under older revisions, but the code always answersisError.Docs
docs/EXTENSIONS.md (
readBodyrow, 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
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) andtest/authoring-errors.test.ts(fixture).npm run verifyandnpm run test:packagepass locally on Node 26 (core packs at 1063194 bytes, within budget).🤖 Generated with Claude Code