ShipShape

Guide

Which env variables are safe to expose in the browser?

A prefix tells the bundler to copy a value into the JavaScript the browser downloads. It is a build-time signal, not a runtime guard. If the value is in that file, it is public.

The prefix is not a lock

Next.js replaces process.env.NEXT_PUBLIC_… with the value from the environment where you run next build. After the build, the app does not read that variable again. Changing it on the host does not change a bundle that is already deployed. Next.js documents that inlining in Environment variables.

Vite does the same for names that start with VITE_. The value is statically replaced at build time and included in the client bundle. Vite’s docs say VITE_ variables should not contain secrets such as API keys. Source: Env variables and modes.

Astro only exposes variables prefixed with PUBLIC_ to client code, and Vite replaces them at build time. Source: Astro environment variables. Current SvelteKit does not use a PUBLIC_ prefix. You mark a variable public: true in src/env.ts and import it from $app/env/public. If you also set static: true, SvelteKit inlines the build-time value. The older $env/static/public module, which did use a PUBLIC_ prefix, is deprecated. Source: SvelteKit environment variables. In every case the mark is a signal to the bundler. It is not a lock on the value.

A server-only name with no public prefix stays on the server, in the frameworks above, only if the client code never reads it. Putting a secret in NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY or VITE_OPENAI_API_KEY ships the secret. The prefix does not make a dangerous value safe, and it does not make a public value private.

Fine to ship

A Supabase publishable key (sb_publishable_…) and the legacy anon key are meant for the browser, a mobile app, or other code you ship. Supabase says the publishable key only reaches what row level security allows, and that the anon key is the legacy form of that key. The secret key and the legacy service_role key bypass RLS. Those stay on the server. Source: Supabase API keys. This scan does not test row level security, so a public anon key is not evidence that the policies are right. The RLS guide is the check you run yourself.

Firebase client config, including the apiKey in that config, is meant to be in the app. Firebase says those API keys are not what controls access to backend data. Security rules do. Source: Firebase API keys. A Firebase private key or service account does not belong in the bundle. This check does not read your rules.

A Stripe publishable key, pk_live_ or pk_test_, is the key Stripe’s client libraries use in the browser. The secret key, sk_, and a restricted key, rk_, are server keys. Source: Stripe API keys.

Never in the browser

Do not ship a Supabase service_role key or a secret key (sb_secret_…). Do not ship a Stripe secret or restricted key, or a webhook signing secret. Do not ship an AI provider key. OpenAI’s help article says to keep API keys private. Anthropic documents API keys as credentials you create in the Claude Console and send on the request. They are not client config. Sources: OpenAI API key safety and Anthropic getting started. Do not ship a database URL. The password in it is the database password. An email provider API key is the same kind of secret: it sends mail as you.

A variable with no public prefix is not automatically safe if you paste the value into a component as a string. The bundler ships the string. The env dashboard never enters into it.

If one already leaked

Rotate the key at the provider, then remove it from the client and from any NEXT_PUBLIC_, VITE_, or PUBLIC_ name, or from a SvelteKit variable marked public. Rebuild and redeploy. The old bundle still contains the old value until every deploy that served it is gone, including preview URLs. If the value was committed, it is still in git history. The shutdown checklist is the longer version of that rotation.

The free check looks at the public URL you give it: the HTML, the same-origin scripts, and seven fixed paths. It can show a secret that is in that material. It does not read the host’s environment dashboard, and it does not test row level security. The Launch Report opens that same pass. It does not scan anything new. If you keep shipping, Monitor repeats the same passive check each week and when a deploy hook fires.

Questions

Is NEXT_PUBLIC_ a security boundary?

No. Next.js inlines NEXT_PUBLIC_ values into the browser bundle at build time. The prefix is a signal to the compiler. It is not a runtime guard, and a later change to the variable does not change a bundle that is already built.

Is the Supabase anon key safe in the browser?

The anon key, and the newer publishable key, are meant to be public. Supabase says they only reach what row level security allows. They are safe to ship only if RLS and the policies are right. This scan does not check that.

Does a VITE_ prefix hide the value from the built site?

No. Vite exposes VITE_ variables to client code and includes them in the bundle. Vite’s docs say those variables should not contain secrets.

What should I do if a secret was prefixed and deployed?

Rotate it at the provider, remove it from client code and from git if it was committed, and rebuild. The old JavaScript still contains the old value anywhere that bundle is still served, including preview deploys and caches.

Run a free check

Newsletter

One tip a week

Get one practical security tip for AI-built apps each week. No spam, unsubscribe anytime.