Skip to content

Store: refuse lone surrogates at every JSON boundary, drop the textual \ud list fallback, and let editable gate increments - #996

Merged
jimhoyd merged 5 commits into
mainfrom
claude/surrogates-988
Sep 29, 2026
Merged

jimhoyd merged 5 commits into
mainfrom
claude/surrogates-988

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 29, 2026

Copy link
Copy Markdown
Collaborator

Fixes #988
Fixes #989
Fixes #990

Problem

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: json routes, with or without a schema: 400, on the server and on the built Worker.

Both check values and object keys, with one iterative walk (holdsIllFormedString in body-validation.ts).

The store adds defence for paths that don't go through HTTP:

  • StoreExports and host transactions answer 422 invalid_record with issue keyword unicode, and the transaction rolls back.
  • Declarations (defaults, transition from/set, states, intervals.when) are refused at activation.
  • A list cursor holding one is 400 invalid_query.
  • A stored row holding one refuses activation with 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 \ud detector 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 that C:\udo, \uD800 and similar ordinary text stay on the SQL path with pages identical to the reference. It also proves that a hand-written lone-surrogate row is 503 on a list and refused at activation.

#989: the lock means what the docs promise. editable now 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 without editable. No per-increment opt-out was added.

Docs

Tests

npm run verify and npm run test:package pass 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

…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
jimhoyd enabled auto-merge (squash) September 29, 2026 22:56
@jimhoyd
jimhoyd merged commit d6b506c into main Sep 29, 2026
26 checks passed
@jimhoyd
jimhoyd deleted the claude/surrogates-988 branch September 29, 2026 23:40
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant