Remote / foldkit-remote-server

Hardening

The handler applies bounded, protocol-level safeguards before or around Sources:

  • a read batch may name at most maxIdsPerEntity distinct ids for one Entity (default 1000); oversized client batches fail rather than loading unbounded rows. Remote's client cuts its batches to the same default, and to the number given in Remote.clientLayer(…, { maxIdsPerEntity });
  • a request body may be at most maxBodyBytes (default 1 MiB) where bytes are read: serveFetch's option, and bodyLimit in front of an RpcServer route. A larger one is a 413, { error, tooLarge: { limit } }, refused by its content-length before anything else, or cancelled the moment the bytes read pass the limit, and never decoded;
  • nested resolution is bounded by maxDepth (default 8);
  • the wire decoder also rejects a selection deeper than MAX_RELATION_DEPTH (8) or more than MAX_FIELDS_PER_REQUEST (256) fields for one Entity;
  • a collection relation read with no window is the Source's to bound: foldkit-remote-drizzle's source reads at most maxCollection children of one row (default 100) and refuses a read that finds more, rather than answering a list cut short;
  • returned field names are copied with Object.hasOwn into null-prototype objects, so names such as __proto__ or toString cannot reach prototypes;
  • a Source's failure, a thrown error and a defect reach the caller as Internal error and an incident id, never in their own words, unless the Source wrote them for the caller with RemoteServer.tell (see When the server fails).

A live subscription is held to the same bounds, checked once by the handler before any live Source or the hub sees it: more than maxIdsPerEntity ids of one Entity (the first of each live list of it counted with them), or more pages of one relation than a read may ask, fails the stream with RemoteLiveRefused and nothing is read; more than MAX_LIVE_QUERIES (32) live lists fails the wire decoder before that. That matters most for a polling Source such as pollLive, which re-reads every subscribed row each tick. A refusal is not truncation: the client does not reconnect it, and liveStatus(Data, …) reads Refused. A hand-written live Source can rely on what it is given having passed, and is responsible for any further bounds its backend needs.