env.inspector
02 / 10Danger pattern"use client"props serializationRSC payload

The Client Component prop leak

A file marked "use client" can't magically read server-only variables — but it can still leak one, if a Server Component hands it over as a prop. The leak isn't in the client code; it's in the handoff.

Demo A — reading process.env directly (safe by design)

ClientSafeDemo is a Client Component that reads process.env.STRIPE_SECRET_KEY itself, with no help from a parent. Since that variable was never prefixed with NEXT_PUBLIC_, Next.js never inlined a value for it in this bundle.

process.env.STRIPE_SECRET_KEY → undefined
process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY → undefined
ClientSafeDemo.jsx
'use client'

export default function ClientSafeDemo() {
  const value = process.env.STRIPE_SECRET_KEY
  // → undefined in the browser, every time, regardless of the
  //   real value on the server. Next.js only inlines NEXT_PUBLIC_*.
  return <div>{String(value)}</div>
}

Demo B — the actual leak: passing it down as a prop

This page (a Server Component) reads process.env.STRIPE_SECRET_KEY and passes it straight into ClientLeakDemo as a prop, the way you might pass a value down to render it nicely. Watch what happens.

<ClientLeakDemo secret="…"> received:
page.jsx (Server Component)
import ClientLeakDemo from './ClientLeakDemo'

export default function Page() {
  // DANGER — this value now has to cross the server/client boundary,
  // which means React serializes it into the page's initial payload.
  return <ClientLeakDemo secret={process.env.STRIPE_SECRET_KEY} />
}
✕Why the NEXT_PUBLIC_ prefix didn't save you here
The prefix system only controls whether Next.js inlines a value into compiled client JavaScript. It has no idea a Server Component just handed the same value to a Client Component as a prop through a completely different path — serialized props in the React Server Components payload. Both routes end up in the browser; the framework only automatically blocks one of them.
Verify it yourself
  1. 1
    View source on this page and search for sk_test_DEMO. You'll find the full secret key sitting in the HTML, inside the RSC payload React streamed down for ClientLeakDemo.
  2. 2
    Open DevTools → Network, reload the page, and inspect the document response for this URL. The same string is right there in the response body — this is not something that requires reading minified JS to find.
  3. 3
    Now search the same response for STRIPE_SECRET_KEY without a prefix mismatch — you'll only find it near the leaked component, not anywhere near Demo A, which never touched it.
✓The fix
Don't pass secrets to Client Components at all. If the UI needs something derived from a secret — "is Stripe connected?", "last 4 digits", a computed total — compute that derived, non-sensitive value on the server and pass that down instead.
Self-check0/3 answered
  • A Client Component can read a server-only variable if it imports process.env itself.

  • Passing a server-only variable as a prop into a Client Component can leak it to the browser.

  • The safest fix is to keep passing the secret down, but rename the prop to something less obvious.