Env Exposure

Server env vars in client components, .env not in .gitignore

criticalSecurityenv-exposure

Severity depends on context. Critical for known secrets (DATABASE_URL, STRIPE_SECRET_KEY, JWT_SECRET and similar) and for a .env file that isn't in .gitignore. Warning for other server variables, which are simply undefined in the browser.

Why this matters

Server-only env vars accessed in client components get bundled into JavaScript that ships to every user's browser. Your database URL, API keys, and secrets become public.

Example

Flaggedcomponents/api-status.tsx
"use client";

export function ApiStatus() {
  // This gets bundled into client JS
  const url = process.env.DATABASE_URL;
  return <span>{url ? "Connected" : "Down"}</span>;
}
Fixedcomponents/api-status.tsx
"use client";

export function ApiStatus() {
  // Only NEXT_PUBLIC_ vars are safe in client code
  const url = process.env.NEXT_PUBLIC_API_URL;
  return <span>{url ? "Connected" : "Down"}</span>;
}

How to fix

Never reference server-only env vars in 'use client' files. Use NEXT_PUBLIC_ prefix for values that are safe to expose. Fetch server data via API routes or server components instead.

Reference

In the output
Findings carry "ruleId": "env-exposure" in --json and the same id in SARIF and in the terminal.
Silence one line
// prodlint-disable-next-line env-exposure
Silence a whole file
// prodlint-disable env-exposure at the top of the file
How it works
Matches text patterns. Source on GitHub