React Server Components (Part 8): Security Boundaries and Data Leakage
Secure React Server Component applications against data leakage, broken authorization and unsafe Server Functions. Learn DTO boundaries, serialization, cache isolation and patching strategy.

React Server Components can improve security architecture because sensitive code and data access can remain on the server.
They can also create a dangerous false sense of safety.
A component running on the server does not automatically mean every value it touches stays on the server. Props can cross into Client Components. Server Functions can be called by hostile clients. Cached results can be shared too broadly. Rendered HTML can reveal data. Framework transport layers have their own security advisories and patch requirements.
The right model is:
RSC gives you a server boundary. You still have to design what is allowed to cross it.
Server-only code is a valuable boundary
Database clients, secret-bearing SDKs and privileged service code should live in server-only modules.
import 'server-only'
import { db } from './db'
export async function getAccountForUser(userId: string) {
// server-side data access
}
Framework tooling can then help prevent accidental imports into the client graph.
This is stronger than relying on naming conventions such as privateDbHelpers.ts and hoping nobody imports the file from a Client Component six months later.
Do not pass database rows directly to Client Components
Suppose your user table contains:
{
id,
email,
displayName,
passwordHash,
mfaSecret,
billingCustomerId,
internalRiskScore
}
Your avatar component needs displayName.
Do this:
<UserMenu user={{
id: user.id,
displayName: user.displayName,
}} />
Not this:
<UserMenu user={user} />
Even if today’s Client Component only reads one property, the broader object has crossed a boundary where it may be serialized into data delivered to the browser.
Use explicit data-transfer shapes.
Minimise before serialization
A useful pattern is to create dedicated functions that return client-safe values:
type PublicUser = {
id: string
displayName: string
avatarUrl: string | null
}
function toPublicUser(user: UserRecord): PublicUser {
return {
id: user.id,
displayName: user.displayName,
avatarUrl: user.avatarUrl,
}
}
This is not glamorous architecture. It is extremely effective architecture.
It makes data exposure reviewable in code review.
HTML is also disclosure
You can leak sensitive information without passing anything to a Client Component.
If a Server Component renders:
<p>Internal fraud score: {account.riskScore}</p>
then the browser receives that output.
“Rendered on the server” means execution happened on the server. It does not mean the rendered result is secret.
Authorize data access, not only routes
A route may require authentication and still contain an IDOR/BOLA vulnerability.
For example:
const invoice = await getInvoice(params.invoiceId)
If getInvoice returns any invoice by ID without checking the current user’s access, changing the route parameter may expose another customer’s invoice.
Prefer a data-access boundary that requires the actor context or derives it server-side:
const invoice = await getInvoiceForUser(params.invoiceId, session.user.id)
Every protected object lookup needs an authorization story.
UI checks are not authorization
This is not security:
{user.isAdmin && <DeleteButton id={project.id} />}
It is useful UI.
The Server Function behind that button must independently verify that the current user may delete the specific project.
Anything callable from the browser must assume the browser can call it outside the path your interface intended.
Server Function arguments are untrusted
React explicitly warns that arguments supplied to Server Functions are fully client-controlled.
Validate:
- identifiers;
- strings and lengths;
- enum-like values;
- URLs;
- file metadata/content as appropriate;
- ownership relationships;
- requested state transitions.
TypeScript cannot validate a network request at runtime.
Cache keys can become security boundaries
Imagine:
cache(async () => getCurrentUserDashboard())
If a persistent cache reuses that result across requests without including the user/tenant identity correctly, one user’s data can be served to another.
The precise behaviour depends on the cache API and framework, but the principle is universal:
Never share a cached result more broadly than the authorization scope of the data inside it.
Personalized caching deserves explicit threat modelling.
Multi-tenant applications need tenant isolation everywhere
In a multi-tenant system, a user ID alone may not be enough context.
Queries, cache keys, object storage paths, background jobs and Server Functions should consistently enforce tenant boundaries.
A convenient server-side query such as:
SELECT * FROM Documents WHERE Id = @id
may be insufficient if the secure lookup is actually:
SELECT * FROM Documents
WHERE Id = @id
AND TenantId = @tenantId
RSC does not change this. It can merely make the insecure query easier to place directly beside the component.
Avoid secret-bearing environment variables in client graphs
Server-only environment variables should only be read from server code.
Client-exposed environment mechanisms in frameworks are intentionally public. If a value is embedded into client JavaScript, assume every visitor can read it.
Never put API secrets into a “public” environment variable because the browser needs to call a privileged API. Put the privileged call behind an authenticated server boundary instead.
Taint APIs are defence in depth, not your whole policy
React has experimental taint APIs intended to help prevent sensitive values or object references from crossing to client code.
They can be useful additional safeguards where supported.
They should not replace explicit client-safe DTOs, authorization or code review. Experimental APIs can also change, so pin their use to the React/framework versions you actually deploy.
Treat RSC transport as framework infrastructure
The RSC wire format and bundler integration are not an API surface most application teams should implement themselves.
React’s own documentation notes that while Server Components and Server Functions are available to applications through supported frameworks, lower-level APIs used by bundlers/frameworks do not necessarily follow the same stable semver guarantees.
Use a maintained framework unless you have a compelling reason and expertise to own that infrastructure.
Patch aggressively
This became particularly important after security vulnerabilities disclosed in the React Server Components ecosystem beginning in late 2025.
The lesson is broader than any one CVE: server-side framework features create remotely reachable parsing, serialization and action-handling surfaces. When React or your RSC framework publishes a security release, treat it like server infrastructure.
Maintain:
- an inventory of deployed React/framework versions;
- automated dependency alerts;
- a fast patch path;
- staging/security regression tests;
- rollback capability;
- awareness of hosting-provider mitigations without relying on them as a substitute for patching.
Keep framework versions aligned
RSC depends on cooperation between React, the framework and bundler/runtime integration.
Do not casually force mismatched package versions to silence a dependency warning.
Test upgrades as a set and follow the framework’s supported version matrix.
Content Security Policy still matters
RSC can reduce application JavaScript, but your page still runs client code and third-party scripts.
A strong CSP remains useful defence in depth against script injection. So do secure cookies, HSTS, framing protection and the other browser security controls covered elsewhere in SiteTidy’s security guides.
Server Components complement browser hardening; they do not replace it.
Avoid sensitive data in logs and error output
Server-side rendering often centralises data access, which can tempt developers to log whole objects while debugging.
Do not log:
- access tokens;
- passwords;
- session cookies;
- payment details;
- private form bodies;
- secret configuration;
- complete database records containing sensitive fields.
Use structured, redacted telemetry.
Production error UI should expose safe messages and correlation IDs rather than stack traces or raw upstream errors.
Threat-model the boundaries
For a sensitive route, draw the flow:
Browser
|
| RSC navigation / action request
v
React framework
|
+--> authentication
+--> authorization
+--> Server Component / Server Function
+--> data access
+--> cache
+--> external services
|
v
serialized/rendered response
|
v
Browser
Then ask at each arrow:
- What input is trusted?
- What identity is established?
- What authorization is enforced?
- What data can cross?
- What is cached?
- What gets logged?
That exercise finds more real problems than asking whether the component has 'use client' at the top.
Audit the exposed web surface too
SiteTidy can inspect production-facing technical and security configuration while your application review covers authorization and data flow.
Security checklist
For an RSC application:
- server-only dependencies are marked/enforced as server-only;
- Client Components receive minimal DTOs rather than raw database entities;
- protected object reads enforce authorization;
- every Server Function treats arguments as hostile input;
- mutations authorize the actor and specific resource;
- personalized caches cannot cross user or tenant boundaries;
- secrets never enter client-exposed environment configuration;
- production errors and logs are redacted;
- CSP and standard HTTP/browser protections remain in place;
- React and framework security releases are tracked and applied quickly;
- package versions remain within supported combinations.
The principle to keep
The most useful security feature of RSC is not that code “runs on the server.”
It is that RSC gives you a strong opportunity to keep privileged capabilities on one side of a boundary and send only the result the browser actually needs.
Take advantage of that boundary deliberately. Minimise, validate, authorize, isolate and patch.
