Skip to content

[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

Closed

Description

@jimhoyd

Runtime revision and environment

main at 21b4dfd (includes #996), Node 24, macOS, run as a store node:test.

Minimal reproduction

A shared collection with a stamped actor:

docs: { mount: '/api/docs', schema: { type: 'object', additionalProperties: false, required: ['title'], properties: { title: { type: 'string', maxLength: 20 }, status: { type: 'string', enum: ['draft', 'done'] }, by: { type: 'string', maxLength: 128 } } },
  defaults: { status: 'draft' }, readOnlyProperties: ['status', 'by'],
  transitions: { finish: { from: { status: 'draft' }, set: { status: 'done' }, stamp: { by: 'actor' } } } }

Trusted host code (StoreExports) then runs a transition with a principal id that is not valid:

const { record } = await exports.records('docs').create(null, { title: 'a' });
await exports.records('docs').transition({ id: '\ud800x' }, record.id, 'finish');   // accepted

A host transaction behaves the same: tx.records('docs').transition({ id: '\udc00' }, id, 'finish').

Expected: 422 invalid_record, as SECURITY.md says for StoreExports and host transactions ("Every stored string is well-formed Unicode").
Actual: the transition is accepted and the stored by is not well-formed. After that:

  • GET /api/docs and GET /api/docs/<id> answer 503;
  • the next activation is refused;
  • writes of other records still succeed.

The same path also skips schema validation of the stamped value. A 200-character id against maxLength: 128, or 'x y' (outside principalIdPattern), is stored. The 200-character case also breaks reads with 503 and refuses restart ("a stored record no longer matches the collection schema").

HTTP is not affected, because core asserts principalIdPattern on principals from authorize(). The gap is reachable only by trusted code that passes a principal. It becomes a denial of service for the collection if application code derives a principal from caller input.

Relevant output

lone surrogate transition: accepted
stored by (len, wellFormed): 2 false
GET list after: 503 {"error":{"code":"storage_unavailable","message":"This collection was redeclared by a reload; try again"}}
restart refused: Collection docs: record … holds by as a string with an unpaired UTF-16 surrogate …
200 chars > maxLength 128 transition: accepted
200 chars > maxLength 128 restart refused: Collection docs: a stored record no longer matches the collection schema

Root cause (from reading the code)

  • packages/store/src/collection.ts around line 1637 stamps actor ?? 'anonymous' without validated(), the unicode check or principalIdPattern.
  • caller() (around line 1483) does not validate the principal for a by: any transition without members.
  • packages/store/src/records.ts ownerOf/actorOf (around lines 125-127) take principal.id as given.

Suggested fix: validate the principal id in records.ts, the same way the owned-collection path does through principal(), and run stamped values through the property checks.

Second, smaller problem

When a stored row fails validation on read, the answer is 503 with the message "This collection was redeclared by a reload; try again" (collection.ts around line 915). For a bad row that message is wrong, and retrying never helps.

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