LeakyVibe

Guides · Updated 2026-10-22

Is my v0 / Vercel app leaking environment variables? NEXT_PUBLIC_ explained

Short answer: Only if a secret ended up in a variable the browser gets. In Next.js (which v0 apps use), environment variables stay on the server by default, but anything prefixed with NEXT_PUBLIC_ is copied into the JavaScript bundle at build time, so every visitor can read it. Vite apps (common with Lovable and Bolt) do the same with VITE_. Marking a variable as Secret in Vercel doesn't change that: it only hides the value in the dashboard. Publishable keys (Supabase anon or sb_publishable_, Stripe pk_) are fine in a public variable. Secret keys (Stripe sk_, Supabase service_role or sb_secret_, OpenAI and other AI keys) must never have a public prefix. If one did, treat it as leaked: rotate it, then move the call to server-side code.

Does your app have this problem? Free scan, 15 sec, no sign-up

or watch it scan our demo app ▶

How NEXT_PUBLIC_ actually works

Next.js docs: by default, environment variables are only available on the server. To make one available in the browser, you prefix it with NEXT_PUBLIC_, and Next.js "inlines" its value at build time, replacing every process.env.NEXT_PUBLIC_... reference with the hard-coded value in the JavaScript sent to the browser (https://nextjs.org/docs/app/guides/environment-variables).

So the prefix is not a label, it's an instruction: "ship this to everyone". Once the app is built, the value sits in a public .js file under /_next/static/. Anyone can open it in DevTools, no login needed.

  • Vite (used by many Lovable and Bolt projects): variables prefixed with VITE_ are exposed in client-side code, and Vite's docs say VITE_ variables should not contain sensitive information such as API keys (https://vite.dev/guide/env-and-mode).
  • The legacy env key in next.config.js: Next.js says variables set this way are always included in the JavaScript bundle, with or without the prefix (https://nextjs.org/docs/app/api-reference/config/next-config-js/env).
  • NEXT_PUBLIC_ values are frozen at build time. Changing the variable in Vercel does nothing until you redeploy, and old deployments keep the old value.

"But I marked it as Secret in Vercel"

Vercel lets you save an environment variable as Config or Secret. Secret values become write-only in the dashboard and long values are redacted from build logs (https://vercel.com/docs/environment-variables/sensitive-environment-variables). That protects the value from people looking at your Vercel project. It does not stop Next.js from inlining it: if the name starts with NEXT_PUBLIC_, the value still ends up in the browser bundle.

Which keys are fine to make public, and which never are

  • Fine in NEXT_PUBLIC_ / VITE_: your Supabase URL and its publishable key (sb_publishable_...) or legacy anon key, Stripe publishable key (pk_...), analytics or map IDs that the provider says are public. With Supabase, what protects your data is Row Level Security on every table, not hiding the anon key (https://supabase.com/docs/guides/api/api-keys).
  • Never public: Supabase secret key (sb_secret_...) or service_role key, which bypass Row Level Security; Stripe secret (sk_) and restricted (rk_) keys; OpenAI, Anthropic, Google AI and other paid API keys; Resend, SendGrid or Twilio keys; database connection strings; webhook signing secrets.

Check your live app in 5 minutes

  1. In your code or .env files, list every variable that starts with NEXT_PUBLIC_ or VITE_. For each one ask: would I be fine posting this value on X? If not, it's a problem.
  2. Check the Vercel project's Environment Variables page for the same prefixes; that's what your production build actually used.
  3. Open your live site, then DevTools > Sources (or Network, filter by JS). Search all files for sk_live, sk_test, sb_secret_, service_role, rk_live and the first few characters of each secret key you use.
  4. Also search the page's HTML source: values passed from server code into a Client Component as props are sent to the browser too.
  5. Look at old preview deployments: they keep the value they were built with until you delete them or protect them.

How to fix it

  1. Assume any secret that was in a public variable is leaked. Rotate it in the provider's dashboard and revoke the old one (see our guide: https://leakyvibe.com/guides/leaked-api-key-what-to-do).
  2. Rename the variable without the public prefix (for example OPENAI_API_KEY instead of NEXT_PUBLIC_OPENAI_API_KEY) and save the new value as a Secret in Vercel.
  3. Move the code that uses it into server-only code: a Route Handler, a Server Action, or a Supabase Edge Function. Check who is calling (signed-in user) and add a rate limit before calling the paid API.
  4. Optionally add import 'server-only' at the top of files that read secrets. Next.js will then fail the build if that file is imported into client code (https://nextjs.org/docs/app/guides/data-security).
  5. Redeploy, re-run the search from the checklist above, and delete or protect old preview deployments that still contain the old value.

A prompt for v0, Lovable, Bolt or Cursor

List every environment variable my app uses and whether it has a public prefix (NEXT_PUBLIC_ or VITE_). For each public one, tell me if it is a publishable key (OK in the browser) or a secret (not OK). For every secret: (1) rename it without the public prefix; (2) move the code that uses it into a server-only Route Handler, Server Action or Supabase Edge Function that checks the user is signed in and rate-limits requests; (3) add import 'server-only' to files that read secrets; (4) make sure no secret is passed as a prop to a Client Component. Don't print any key values. List the files you changed and the variables I need to set in Vercel.

Short checklist

  • No secret key in any NEXT_PUBLIC_ or VITE_ variable, in code, .env files or Vercel settings.
  • Any secret that ever had a public prefix has been rotated.
  • Live JavaScript and HTML searched for sk_, sb_secret_ and service_role: nothing found.
  • Calls to paid APIs go through a server route with auth and rate limits.
  • Old preview deployments deleted or protected.

Want a quick outside check? The free LeakyVibe scan above reads your public pages and same-origin JavaScript, read-only, in about 15 seconds, and flags secret-looking keys, Supabase tables that answer to your public key, public source maps and missing security headers. It's a first check, not a full audit, and it can't see variables that never reach the browser.

Check your app for this now

Free scan · about 15 seconds · no sign-up

Passive, read-only checks. Only scan apps you own or have permission to test.