"SSR is not an API"
Server-Side Rendering is not an API. An API returns data to a caller that then decides what to do with it. SSR renders a document and sends the whole document to the browser. "It ran on the server" and "the browser never sees it" are two different claims — this page stages the mistake of assuming the first implies the second.
process.env.STRIPE_SECRET_KEY directly into this Server Component's JSX, in full. It is a real demo value, but this is exactly what a real leak looks like: no client-side code did this, no fetch call did this, no build misconfiguration did this. A Server Component simply printed a server-only variable into the markup it returned, and that markup is the HTML sent to your browser right now.process.env.STRIPE_SECRET_KEYLeakedRendered in full, on purpose, for this demo only.
export default function Page() {
// This function runs on the server. That part is true.
// But its return value is the HTML sent to the browser — the two
// facts are unrelated to each other.
return <div>{process.env.STRIPE_SECRET_KEY}</div>
}The fix: use the secret, render the outcome
The correct pattern still runs entirely on the server — it just never puts the raw value into what gets returned.
process.env.STRIPE_SECRET_KEYMaskedSame variable, same server, same request. The only difference is what the JSX returns.
export default async function Page() {
const key = process.env.STRIPE_SECRET_KEY || ''
// Use the key server-side — call an API, query a DB, sign something —
// then render only what the browser actually needs to see.
const preview = key.slice(0, 4) + '••••••••' + key.slice(-2)
return <div>{preview}</div>
}- 1View source on this page right now (
Ctrl/Cmd+U) and search forsk_test_DEMO. It's in the raw HTML — no DevTools JS inspection required, because this never touched client-side JavaScript at all. - 2Disable JavaScript entirely in DevTools (Command Menu → "Disable JavaScript") and reload. The leaked value is still on the page. That's the clearest possible proof that this has nothing to do with client-side code.
- 3Compare with the masked card: search the page source for the last four characters of the real key printed above it — you'll find them only inside the first, intentionally-leaky card.
"This code runs on the server" is enough on its own to guarantee a value stays private.
Server-Side Rendering works like calling an API: the server computes something and only the caller who asked for it sees the result.
Disabling JavaScript in the browser would hide a secret that was rendered directly into a Server Component’s HTML.