Back to Common risks

Common risksSecret keys

The NEXT_PUBLIC_ trap

In Next.js and similar frameworks, the NEXT_PUBLIC_ prefix is a deliberate instruction: bundle this value into every visitor's browser. Name a server secret with that prefix and the build tool obeys.

What can go wrong

Frameworks like Next.js only expose environment variables to the browser when their names start with NEXT_PUBLIC_ (or the equivalent public prefix in your stack). That is by design: it is how you ship a public map API key or analytics ID.

The trap is naming something like NEXT_PUBLIC_STRIPE_SECRET_KEY or NEXT_PUBLIC_SUPABASE_SERVICE_ROLE. The prefix tells the bundler to inline the value into client JavaScript. Your .env file can look fine while the production build leaks the secret to everyone.

It happened for real

Researchers scanning live URLs found widespread misuse: in January 2026, supaexplorer reported 11.04% of 20,052 scanned apps exposed Supabase-related secrets, often via public env prefixes and client bundles. Builders have also shipped NEXT_PUBLIC_STRIPE_SECRET_KEY in production.

How to check yours

Seatbelt flags this automatically (partial). We hard-gate when a NEXT_PUBLIC_ variable name clearly marks a server secret (SECRET, SERVICE_ROLE, PRIVATE, sk_, and similar). We also flag obvious NEXT_PUBLIC_ misuse patterns in client code.

Honest hole: value-only fan-out (a benign-looking NEXT_PUBLIC_FOO that still holds a secret value) is not flagged automatically yet. Read your .env, .env.local, and any NEXT_PUBLIC_ names by hand.

Ask your agent: "List every environment variable whose name starts with NEXT_PUBLIC_. For each one, confirm it is safe for any visitor to read. Rename or move anything that is a server secret."

We don't catch this yet: Hosting-dashboard env vars that never appear in the repo export.

Fix direction

Rename server secrets to names without the public prefix. Keep them in server-only code paths. Only pk_ publishable keys and truly public IDs belong behind NEXT_PUBLIC_.

Paste into your agent: "Audit all NEXT_PUBLIC_ variables. Remove the prefix from any server secret and move those calls server-side. Rotate any secret that shipped with NEXT_PUBLIC_ in its name."

Related risks