react-server675fbba4
react-servercommita0c7b6386c78

feat: rsc reply (#393)

This PR brings @lazarv/rsc's reply path up to parity with React's post-CVE hardening and completes the wire format on the client → server direction. Two things were missing: our encodeReply/decodeReply only handled synchronous values (plain objects, arrays, typed arrays, maps, sets, files, server refs), and the decoder had no resource ceilings, so a hostile or oversized payload could push the process into unbounded work before any server action ran. Both are addressed here, and the security model is documented so hosts know what the protocol does and doesn't defend against.

On the protocol side, the client encoder now pre-resolves Promises, ReadableStreams, AsyncIterables, and sync Iterators into outlined FormData rows ($@, $r, $b, $x, $X) before the synchronous walker runs, with cycle-safe visit tracking and back-reference reservation so a resolved value containing the same thenable doesn't recurse. The server side is a new reply decoder that matches React's structural defenses: __proto__/constructor/prototype stripped during JSON.parse, reference path walks pinned to Object.prototype/Array.prototype with own-property checks, then functions scrubbed to null, and callables restricted to the server-reference allowlist and temporary-reference proxy — no eval, no new Function on decoded bytes. Errors are redacted to digests in production via an onError hook on the host.

The PR provides seven configurable resource ceilings on top of those structural defenses (maxRows, maxDepth, maxBytes, maxBoundArgs, maxBigIntDigits, maxStringLength, maxStreamChunks), wired through serverFunctions.limits in react-server.config.mjs and surfaced in both schema.d.ts and schema.json. Defaults match React's upstream; breaches throw a tagged DecodeLimitError before the server function runs, so operators get per-limit observability and zero side effects on rejection. The docs commit adds a Security section to the bundler-agnostic RSC serialization page and a new server-function-limits feature page in both English and Japanese, covering the threat model, the always-on structural barriers, the configurable ceilings, and explicitly what remains the host's responsibility (authn/z, CSRF, rate limiting, transport integrity).

Author
Viktor Lázár <lazarv1982@gmail.com>
Date
Commit
a0c7b6386c782f0e6faa490e0d4b20fd4b7a0403
21 files changed+2547 -68