This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
frontendcritical PriorityID: react19-rsc-taint-boundary-guardrail

React 19 Server Component Cryptographic & Credential Taint Boundary Invariants

Enforces strict cryptographic and identity isolation by utilizing React 19's experimental taint APIs alongside server-only boundary declarations. Prevents accidental serialization of raw user records, API keys, and sensitive tokens across the React Server Components (RSC) Flight protocol payload boundary to client components. Mandates explicit data projection patterns to sanitize all payloads traversing the server-client boundary.

Prohibited Anti-Pattern: Leaking Sensitive Entity Objects and Tokens Across RSC Serialization Boundaries Without Taint Traps

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: React 19 Server Component Cryptographic & Credential Taint Boundary Invariants - Enforces strict cryptographic and identity isolation by utilizing React 19's experimental taint APIs alongside server-only boundary declarations. Prevents accidental serialization of raw user records, API keys, and sensitive tokens across the React Server Components (RSC) Flight protocol payload boundary to client components. Mandates explicit data projection patterns to sanitize all payloads traversing the server-client boundary.
globs: src/**/*.{ts,tsx}, app/**/*.{ts,tsx}, server/**/*.{ts,tsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/react19-rsc-taint-boundary-guardrail"
---

# React 19 Server Component Cryptographic & Credential Taint Boundary Invariants

> **Severity**: CRITICAL | **Category**: frontend
> **Anti-Pattern Warning**: Leaking Sensitive Entity Objects and Tokens Across RSC Serialization Boundaries Without Taint Traps

## System Constraints
You are a Principal Security Architect and React Core Engineer enforcing React 19 experimental taint boundaries. Your objective is to ensure that no raw database entity, secret token, password hash, or sensitive PII is ever passed across Server Component boundaries to Client Components. Enforce 'experimental_taintObjectReference' on sensitive domain models and 'experimental_taintUniqueValue' on cryptographic secrets immediately upon retrieval.

## Strict Guidelines
- Engineers MUST ALWAYS import and execute 'experimental_taintObjectReference' on raw domain entities containing sensitive metadata (e.g., User, Organization, PaymentProfile) immediately within the server-side data access layer.
- Engineers MUST ALWAYS apply 'experimental_taintUniqueValue' to individual sensitive credentials (e.g., API keys, hashed passwords, auth session secrets, JWTs) before passing data through any pipeline.
- Engineers MUST NOT pass whole server entity objects into Client Components marked with 'use client'; only explicit, sanitized DTOs (Data Transfer Objects) mapping only explicitly public fields may cross the boundary.
- Code SHOULD enforce 'import "server-only"' at the root of any module that initializes taint wrappers or handles untrusted raw database queries.
- Services MUST return strictly projected, shallow primitives to client components rather than passing complex instances with hidden property descriptors.
- Components NEVER accept raw database entity types as props across a 'use client' boundary.

## Bad vs Good Implementations
### Tainting Raw User Objects & Providing Explicit Safe DTOs

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The entire database entity containing sensitive fields (like password hashes or session tokens) is passed directly to a Client Component. Even if UserProfileCard does not render the password hash, the React Server Components wire protocol serializes the entire object payload into the client's initial HTML and Flight stream, exposing internal credentials to the browser.
```typescript
import { db } from '@/lib/db';
import { UserProfileCard } from '@/components/UserProfileCard'; // 'use client' component

export async function UserPage({ params }: { params: { id: string } }) {
  // Anti-pattern: Fetching raw record with password hash, secret salt, and tokens
  // and forwarding the full entity across the RSC wire boundary.
  const user = await db.user.findUnique({ where: { id: params.id } });
  if (!user) return null;

  // LEAK RISK: Serialized into RSC JSON payload; client receives passwordHash
  return <UserProfileCard user={user} />;
}
```

#### Production Standard (Correct)
> **Standard**: The raw user entity and its cryptographic hash are explicitly protected using React 19's experimental taint APIs within a 'server-only' data layer. If any engineer or refactor attempts to pass 'user' to a Client Component, React throws an explicit build or runtime error. Only a strictly typed PublicUserDto is passed to the client.
```typescript
import 'server-only';
import { experimental_taintObjectReference, experimental_taintUniqueValue } from 'react';
import { db } from '@/lib/db';
import { UserProfileCard } from '@/components/UserProfileCard'; // 'use client' component

export interface PublicUserDto {
  id: string;
  displayName: string;
  avatarUrl: string | null;
}

export async function getUser(userId: string) {
  const user = await db.user.findUnique({ where: { id: userId } });
  if (!user) return null;

  // Invariant: Register taint barriers on the raw object and unique cryptographic values
  experimental_taintObjectReference('Do not pass raw user record to the client', user);
  experimental_taintUniqueValue('Do not pass password hash to the client', user, user.passwordHash);

  return user;
}

export async function UserPage({ params }: { params: { id: string } }) {
  const user = await getUser(params.id);
  if (!user) return null;

  // Explicit projection prevents taint violations and protects data
  const clientSafeDto: PublicUserDto = {
    id: user.id,
    displayName: user.displayName,
    avatarUrl: user.avatarUrl,
  };

  return <UserProfileCard user={clientSafeDto} />;
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: React 19 Server Component Cryptographic & Credential Taint Boundary Invariants

React 19 Server Component Cryptographic & Credential Taint Boundary Invariants defines an industrial-grade behavioral standard for frontend engineering. Enforces strict cryptographic and identity isolation by utilizing React 19's experimental taint APIs alongside server-only boundary declarations. Prevents accidental serialization of raw user records, API keys, and sensitive tokens across the React Server Components (RSC) Flight protocol payload boundary to client components. Mandates explicit data projection patterns to sanitize all payloads traversing the server-client boundary. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Leaking Sensitive Entity Objects and Tokens Across RSC Serialization Boundaries Without Taint Traps Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftLeaking Sensitive Entity Objects and Tokens Across RSC Serialization Boundaries Without Taint TrapsCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS import and execute 'experimental_taintObjectReference' on raw domain entities containing sensitive metadata (e.g., User, Organization, PaymentProfile) immediately within the server-side data access layer.

Engineers MUST ALWAYS import and execute 'experimental_taintObjectReference' on raw domain entities containing sensitive metadata (e.g., User, Organization, PaymentProfile) immediately within the server-side data access layer.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST ALWAYS apply 'experimental_taintUniqueValue' to individual sensitive credentials (e.g., API keys, hashed passwords, auth session secrets, JWTs) before passing data through any pipeline.

Engineers MUST ALWAYS apply 'experimental_taintUniqueValue' to individual sensitive credentials (e.g., API keys, hashed passwords, auth session secrets, JWTs) before passing data through any pipeline.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Engineers MUST NOT pass whole server entity objects into Client Components marked with 'use client'

Engineers MUST NOT pass whole server entity objects into Client Components marked with 'use client'; only explicit, sanitized DTOs (Data Transfer Objects) mapping only explicitly public fields may cross the boundary.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Code SHOULD enforce 'import "server-only"' at the root of any module that initializes taint wrappers or handles untrusted raw database queries.

Code SHOULD enforce 'import "server-only"' at the root of any module that initializes taint wrappers or handles untrusted raw database queries.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Services MUST return strictly projected, shallow primitives to client components rather than passing complex instances with hidden property descriptors.

Services MUST return strictly projected, shallow primitives to client components rather than passing complex instances with hidden property descriptors.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
6

Components NEVER accept raw database entity types as props across a 'use client' boundary.

Components NEVER accept raw database entity types as props across a 'use client' boundary.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is React 19 Server Component Cryptographic & Credential Taint Boundary Invariants critical for AI coding assistants?

Enforces strict cryptographic and identity isolation by utilizing React 19's experimental taint APIs alongside server-only boundary declarations. Prevents accidental serialization of raw user records, API keys, and sensitive tokens across the React Server Components (RSC) Flight protocol payload boundary to client components. Mandates explicit data projection patterns to sanitize all payloads traversing the server-client boundary. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Leaking Sensitive Entity Objects and Tokens Across RSC Serialization Boundaries Without Taint Traps) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

Related FRONTEND Rules

View all rules →
frontend
119

SolidStart 1.0 Server Functions & Async Boundaries Production Standard

SolidStart 1.0 relies on the Vinxi bundler to split `server$` closures into independent HTTP POST RPC endpoints. Direct lexical closure over client signals within `server$` scopes or failure to demarcate async boundaries with `<Suspense>` causes silent serialization failures, client-bundle secret leaks, and SSR hydration mismatches. Enforcing strict parameter passing, runtime input validation, and Solid async primitives maintains security and fine-grained reactivity across network boundaries.

frontend
119

Astro 5 Actions & Content Layer Production Standard

Enforces strict type safety and architectural correctness for Astro 5 Server Actions and the zero-waterfall Content Layer API. Prevents runtime contract mismatches, hydration mismatches, and unhandled mutation exceptions across dynamic and prerendered boundaries. Failure to follow these patterns leads to silent data fetching waterfalls, build-time cache corruptions, and unhandled server action exceptions.

frontend
51

Nuxt 4 Nitro Server Engine & Shared Directory Production Standard

Nuxt 4 enforces strict boundary segregation between client UI in the app/ directory, backend endpoints in server/, and universal contracts in shared/. Violating cross-boundary isolation or maintaining module-scoped state in Nitro server handlers causes catastrophic cross-request data corruption and hydration mismatches under concurrent production traffic. Architects must enforce request-isolated H3 event contexts, universal serialization schemas, and strict path-alias boundaries.

1 Rule in Stack

React