Privacy of serialized data
What you need to know
Server-only execution does not automatically make the data returned by that execution private. A data transfer object (DTO) is a deliberately small object that includes only fields the recipient actually needs.
By the end, you can: review client props and logs; separate public and private cache.
Project the public article DTO
type Article={id:string;title:string;owner:string;reviewNote:string};function toPublic(row:Article){return {id:row.id,title:row.title};}const row={id:'a1',title:'Reading trail',owner:'editor-a',reviewNote:'synthetic private note'};console.log(JSON.stringify(toPublic(row)));Expected behavior: {"id":"a1","title":"Reading trail"}. Neither the owner nor the note is copied.
How it works
A database row might contain a public title, owner identifiers, draft notes and internal review metadata. Passing the entire row to an interactive component crosses the server/client boundary even if the component never displays some fields. Construct a fresh allowlisted DTO on the server after access checks. TypeScript's Pick type documents a shape but does not remove properties from an existing object at runtime; object spreading can accidentally retain fields. Apply the same discipline to JSON responses, serialized error state, metadata, logs and analytics. For this application, public article data is separate from authenticated draft reads. Private responses explicitly opt out of HTTP storage, and the DAL is not wrapped in a persistent shared cache. HTTP Cache-Control does not by itself control every framework cache or an already-delivered browser value. Avoid secrets in URLs, client props and log payloads. Treat production bundle and response inspection as separate evidence from source review.
Return a minimal authenticated response
// Fragment: row already authorized by the DALfunction privateArticle(row:{id:string;title:string;revision:number}) { return Response.json({id:row.id,title:row.title,revision:row.revision}, { headers:{'Cache-Control':'private, no-store'} });}Expected behavior: The client receives only three named fields. The response declares a no-store policy for HTTP caches. Test Next.js caching configuration separately.
Common mistake
An assertion such as row as PublicArticle changes how TypeScript checks code, not the contents of row. Use a new object with explicit fields. Never include a private value just because it is not shown in JSX.
Practice and verification
Add a synthetic marker to a private fixture field. Search the public DTO, JSON response, rendered HTML and browser navigation payload for the marker; separately inspect client bundles and redacted logs. Source-level absence alone does not establish runtime absence.
Scope: App Router, proposed Next.js 16.x and React 19, Cache Components disabled. Framework snippets are staged, not executed; local policy, SQLite and HTTP transport evidence is separate. Exact patched dependencies and platform contracts are pending.
Further reading: Security Data · Components · Auth