NEXT_PUBLIC_, VITE_, and EXPO_PUBLIC_ secrets: which env vars are actually public
Short answer
NEXT_PUBLIC_ (Next.js), VITE_ (Vite), EXPO_PUBLIC_ (Expo), NUXT_PUBLIC_ (Nuxt), and PUBLIC_ (SvelteKit) are compile-time public prefixes. The bundler replaces them with the literal value and ships it to every visitor. Put publishable keys, site URLs, and analytics IDs there. Put LLM keys, Stripe secret keys, database URLs, webhook secrets, and Supabase sb_secret_ keys in server-only variables and never import those variables into client code. Search the production build, not just the repository.
Last updated · Sekrd Research
- Next.js inlines
NEXT_PUBLIC_into the browser bundle at build time. Other env vars are only available on the server, unless a Client Component imports them. - Vite exposes only variables prefixed
VITE_, and it exposes all of them, viaimport.meta.env. - Expo inlines
EXPO_PUBLIC_. Nuxt usesNUXT_PUBLIC_in runtime config that is sent to the client. SvelteKit usesPUBLIC_.
The rule
If the framework documents a prefix as “available in the browser,” the value is not a secret. The prefix is the bug when the name after it is a server credential. These are the pairs that should not exist:
| Prefix | Where it leaks | Safe examples | Never with this prefix |
|---|---|---|---|
NEXT_PUBLIC_ | Next.js client bundle | Site URL, Supabase publishable key, analytics id | LLM keys, STRIPE_SECRET, DATABASE_URL, sb_secret_, webhook secrets |
VITE_ | Vite bundle, import.meta.env | Same publishable values | Same server secrets |
EXPO_PUBLIC_ | Expo / React Native JS bundle | Public API host, publishable key | Same server secrets |
NUXT_PUBLIC_ | Nuxt payload sent to the browser | Public runtime config | Private runtime config belongs under runtimeConfig without public |
PUBLIC_ | SvelteKit, $env/static/public | Public values only | Private values belong in $env/static/private or $env/dynamic/private |
Next.js will also leak a server variable if you import it into a Client Component. The prefix is the common case; the import is the other one. Read the variable inside a Server Component, a route handler, or a Server Action, and pass the client only the result of the call, not the key.
How to check your app
- Search source for the dangerous names. This catches the mistake before a build.
git grep -n -E "(NEXT_PUBLIC_|VITE_|EXPO_PUBLIC_|NUXT_PUBLIC_|PUBLIC_).*(SECRET|SERVICE_ROLE|DATABASE_URL|OPENAI|ANTHROPIC|STRIPE_SECRET|WEBHOOK|PRIVATE_KEY)" \
-- ':!node_modules' ':!*.lock'
Sekrd’s free-scan check is the same idea applied to the shipped JavaScript: a client prefix plus a server-secret name, skipping comments and placeholders such as example, your_, and changeme. It does not flag NEXT_PUBLIC_SUPABASE_URL or a publishable key.
- Search the production build. Inlining happens at compile time, so a clean repo can still produce a dirty bundle if the variable was set in CI.
npm run build
grep -R -n -E "sk-svcacct-|sk-proj-|sb_secret_|rk_live_|whsec_" .next/static dist build 2>/dev/null
- Fix by renaming and moving, not by obfuscating. Delete the client-prefixed variable. Set
OPENAI_API_KEY(no prefix) in the host’s server environment. Call the provider from the server. Rotate the key if this build was ever deployed — see the first hour. - Repeat for mobile. An Expo app is a client.
EXPO_PUBLIC_is inside the binary people install.
Framework notes that agents get wrong
- Next.js.
.env.localis the right file for local secrets and should be gitignored.NEXT_PUBLIC_values from that file are still public. They are not “local.” - Vite. Only
VITE_variables are exposed, which tempts people to add the prefix to everything the client “needs.” The client does not need the secret. It needs a URL on your server. - Supabase.
NEXT_PUBLIC_SUPABASE_URLandNEXT_PUBLIC_SUPABASE_ANON_KEY(or the publishable key) are the documented client setup.NEXT_PUBLIC_SUPABASE_SERVICE_ROLEor aVITE_variable holdingsb_secret_is a full database bypass. RLS checklist: here.
A free scan reports the client-prefix finding from the live bundle, which is the copy that matters. Plans that add scheduled rescans are on /pricing.
Frequently asked questions
Is NEXT_PUBLIC_ safe for API keys?
No, unless the key is designed to be public, such as a Supabase publishable key. Next.js replaces NEXT_PUBLIC_ variables with their values in the JavaScript sent to the browser. OpenAI keys, Stripe secret keys, database URLs, and Supabase secret keys must be server-only.
Which environment variable prefixes are exposed to the client?
NEXT_PUBLIC_ in Next.js, VITE_ in Vite, EXPO_PUBLIC_ in Expo, NUXT_PUBLIC_ in Nuxt, and PUBLIC_ in SvelteKit. Values under those prefixes are bundled or sent to the browser.
How do I find a leaked NEXT_PUBLIC_ secret?
Search the repository for the prefix plus a secret name, then search the production build output (.next/static, dist, or build) for key prefixes such as sk-proj-, sk-svcacct-, and sb_secret_. Also scan the deployed URL, because CI may have inlined a variable that is not in git.
Sources
Don't ship until you're sekrd
Run a free scan to find the vulnerabilities your AI missed.
Scan Your App Free