Repository navigation
Store: refuse lone surrogates at every JSON boundary, drop the textual \ud list fallback, and let editable gate increments - #996
Merged
Conversation
…ates increments (#988, #989, #990) - Core's JSON body reader (readBody, 400 invalid_unicode) and format: json routes (400) refuse a string or key holding an unpaired UTF-16 surrogate. - The store refuses one through StoreExports, host transactions and declarations (422 invalid_record, keyword unicode), in a list cursor, and at activation for a row an earlier release stored, naming the record. - With no such row possible, the SQL list path drops its textual \ud detector, which ordinary text like C:\udo triggered. - editable now gates POST <mount>/<id>/increment/<property> (409 record_locked); a short link's click count stays ungated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
jimhoyd
enabled auto-merge (squash)
September 29, 2026 22:56
… references Co-Authored-By: Claude Opus 5.5 <[email protected]>
… references Co-Authored-By: Claude Opus 5.5 <[email protected]>
… references Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Sep 29, 2026
jimhoyd
added a commit
that referenced
this pull request
Sep 30, 2026
…fixtures (#1016) (#1022) #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]>
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 #988
Fixes #989
Fixes #990
Problem
\ud800escape) got pastuniqueandintervals.within. SQLite's->>and a bound JS string carry it as different bytes. The next activation then saw the duplicate or overlap and refused the database. Distinct lone-surrogate values also collided onkey.\ud, which ordinary strings likeC:\udomatch.editabledid not stopPOST <mount>/<id>/increment/<property>, so the owner could still change an approved amount.Design
#988: core is the boundary. Nothing legitimate needs lone surrogates in JSON. I-JSON (RFC 7493) forbids them, UTF-8 cannot carry them, and the body is already fatally UTF-8 decoded, so an escape is the only way to produce one. Core therefore refuses them in every JSON body it parses:
readBody, used by every extension including the store:400 invalid_unicode.format: jsonroutes, with or without a schema:400, on the server and on the built Worker.Both check values and object keys, with one iterative walk (
holdsIllFormedStringinbody-validation.ts).The store adds defence for paths that don't go through HTTP:
StoreExportsand host transactions answer422 invalid_recordwith issue keywordunicode, and the transaction rolls back.defaults, transitionfrom/set, states,intervals.when) are refused at activation.400 invalid_query.record <id> holds <property> as a string with an unpaired UTF-16 surrogate … change or delete that record in the database first. Any database written before this change could hold such rows. With no external users there is no migration; the message names the cause.#990: with lone surrogates now impossible in stored rows, the textual
\uddetector and the filter/cursor surrogate check are removed. The anomaly index now flags only a value of another type than declared (a row written under another declaration). The differential test now proves thatC:\udo,\uD800and similar ordinary text stay on the SQL path with pages identical to the reference. It also proves that a hand-written lone-surrogate row is503on a list and refused at activation.#989: the lock means what the docs promise.
editablenow gates the public increment (409 record_locked, after the scope/404 checks), and OpenAPI names it on the increment path. On an owned collection only the owner can increment, which is exactly an edit, so a view counter by other people isn't possible there anyway. A short link's click count, which is store-owned bookkeeping on redirect, stays ungated, and so do transfers. A counter that must keep counting on locked records belongs in a collection withouteditable. No per-increment opt-out was added.Docs
readBody), HTTP.md (format), and the RIM cardsRIM-EXT-HTTP-001andRIM-HTTP-001.Tests
packages/store/test/unicode.test.ts, over real HTTP:uniquereproduction, then a restart that still activates;intervals.withinreproduction with thed1control;keycollisions, including U+FFFD;state-gates.test.ts: the [Bug]: store editable does not stop the owner's increments, so an approved record's value can still change #989 reproduction (a draft still counts, an approved record gets409 record_locked, nothing is written, and 404s come first) and the OpenAPI description.list-order.test.ts: the differential test is updated for [Bug]: store SQL lists (#986): any creator can force every owner's sorted lists onto the in-memory path with an ordinary string #990.readBodyinvalid_unicodecases, plus aformat: jsonroute on the server and the built Worker.npm run verifyandnpm run test:packagepass locally (Node 26, macOS). The core package is 1051593 packed bytes, within its budget. This is not an independent security review.🤖 Generated with Claude Code