Server trust boundaries
What you need to know
A trust boundary is where data or authority crosses between components with different privileges. In Next.js, validate untrusted inputs and authorize operations on the server, even when the interface already hides unavailable actions.
By the end, you can: validate input at actual server endpoint; avoid leaking secrets.
Check a resource before using it
type Actor = { tenant: string; role: 'reader' | 'editor' };function canEdit(actor: Actor | null, tenant: string) { return actor !== null && actor.tenant === tenant && actor.role === 'editor';}console.log(canEdit({tenant:'river',role:'editor'}, 'hill'));Expected behavior: false: an editor of River cannot edit Hill records.
How it works
Treat Route Handlers and exported Server Functions as independently reachable endpoints. Establish the actor from a verified session, parse input from form data or JSON, authorize the requested resource, and perform the operation only after those checks. Client-supplied user IDs are data, not proof of identity. Put database access in a server-side data access layer, and pass a deliberately small data transfer object (DTO) to the client. A server-only import can detect accidental imports into client code, but does not stop a Server Component from returning private values in rendered output or props. Environment variables with NEXT_PUBLIC_ are intended for client exposure; never use that prefix for secrets. Avoid including private values in metadata, error messages or shared caches. The first example is a pure policy with an already verified actor; it is not session verification. In the actual application enforce the same rule in the read/write query or transaction, not just at the UI boundary.
Return only public properties
import 'server-only';type BookRow = { title: string; slug: string; internalCost: number };export function publicBook(row: BookRow) { return { title: row.title, slug: row.slug };}Expected behavior: A caller receives title and slug only. This partial server module assumes a separate authorization check before a private row is read.
Common mistake
Never use a hidden button, layout redirect or Proxy check as the only authorization. Passing a whole ORM record to a Client Component may expose fields that are not displayed.
Practice and verification
Construct two synthetic tenants and an editor, reader and anonymous actor. Test same-tenant success, cross-tenant denial and field minimization. In the real integration also test direct requests and verify denied writes leave the database unchanged.
Scope: Proposed Next.js 16.x / React 19, Cache Components disabled unless noted. Framework and browser examples are staged; local standalone tests are reported separately. Exact dependency patches and platform contracts pending.