PatchPaste · Guides
Last updated 13 November 2026
Are VITE_ environment variables secret?
No. Any variable that starts with VITE_ (or NEXT_PUBLIC_ in Next.js) is copied into your app's JavaScript when it's built. Every visitor downloads that JavaScript, so every visitor can read the value. Putting an OpenAI, Stripe secret or Supabase secret key in a VITE_ variable is the same as publishing it.
Why .env doesn't hide anything
A .env file feels private. It isn't, once a variable has the public prefix.
- Vite says variables starting with
VITE_“will be exposed in client-side source code after Vite bundling”, and that they “should not contain sensitive information such as API keys” (Vite docs). - Next.js puts
NEXT_PUBLIC_values “into any JavaScript sent to the browser” at build time. Variables without that prefix stay on the server (Next.js docs). - Lovable keeps two separate places.
.envholdsVITE_values, which are “embedded into the client bundle at build time”. Secrets hold backend keys likeOPENAI_API_KEYorSTRIPE_SECRET_KEY, which “never reach the browser” (Lovable docs: Secrets).
So the prefix decides who can see the value. The file name doesn't.
Which keys are fine in the browser, and which aren't
| Fine to be public | Must stay on the server |
|---|---|
| Supabase URL | Supabase service_role or sb_secret_... key |
| Supabase anon or publishable key (only with RLS on every table) | OpenAI (sk-...), Anthropic (sk-ant-...) and other AI keys |
Stripe publishable key (pk_live_...) | Stripe secret key (sk_live_...) |
| Email and SMS keys, and database passwords or URLs |
Supabase says the same about its own keys. Publishable and anon keys are “safe to use in a browser when you have Row Level Security enabled”. Secret and service_role keys “bypass Row Level Security, so use them in Edge Functions and never in a browser” (Supabase docs: Edge Function secrets). More: is the Supabase anon key safe to expose?
Check your own app in 2 minutes
- Open your live site (not the editor preview) in a private window.
- Open dev tools → Sources and search all files (Ctrl+Shift+F, or Cmd+Option+F on a Mac) for:
sk-andsk-ant-(AI keys)sk_live(Stripe secret)service_roleandsb_secret_(Supabase admin keys)dangerouslyAllowBrowser(an OpenAI SDK setting that turns off its browser safety check)
- Also watch the Network tab while you use the app. If you see requests going straight to
api.openai.comorapi.anthropic.comfrom the browser, a key is going with them.
The OpenAI SDK won't run in a browser unless you set dangerouslyAllowBrowser: true. Its own docs say this “exposes your secret API credentials in the client-side code” (openai-node README). If your AI editor added that flag, treat the key as public.
Found one? Do it in this order
- Move the call to the server. Create a server function that calls the API, and point your app at it.
- Make a new key in the provider's dashboard and put it only in server-side secrets. Never put it in a
VITE_orNEXT_PUBLIC_variable. - Redeploy, then search your live JavaScript again to confirm no key is there.
- Delete the old key. Removing it from your code isn't enough: old builds, and anyone who copied it, still have it.
- Add limits. Set a spend cap on the new key if the provider offers one, and rate-limit your server function so a stranger can't run up your bill through it.
Fixing the cause before you swap keys stops the new key leaking the same way. This is the order Supabase gives for its own keys. If you see signs the old key is being misused, delete it straight away, even if a feature breaks for a while.
Where the secret goes
- Lovable: use Secrets. Lovable usually asks for the key through a secure input when a feature needs it. It even rejects
VITE_names in Secrets, because those belong in.env(Lovable docs). - Supabase Edge Functions: set it in the dashboard under Edge Function Secrets, or with
supabase secrets set NAME=value. Then read it withDeno.env.get('NAME')(Supabase docs). - Next.js: drop the
NEXT_PUBLIC_prefix and readprocess.env.NAMEonly in a Route Handler or other server code (Next.js docs).
A prompt you can paste into Lovable, Bolt or Cursor
My app calls <service> from the browser using a key in a VITE_ (or NEXT_PUBLIC_) variable. Move this to the server: 1. Create a server function (Supabase Edge Function or server route) that reads the key from server-side secrets, never from a VITE_/NEXT_PUBLIC_ variable. 2. Change the frontend to call that function instead of <service> directly. 3. Require a signed-in user in the function and add a simple rate limit. 4. Remove the old variable and any dangerouslyAllowBrowser setting. Show me the changes before applying them. I will replace the old key myself.
Leaked a Supabase admin key? See what to do if your service_role key is exposed.
VITE_ variables FAQ
Are VITE_ environment variables secret?
No. Vite copies every VITE_ variable into your JavaScript when it builds your app. Every visitor downloads that JavaScript, so anyone can read the value. Vite's own docs say VITE_ variables should not contain sensitive information such as API keys.
Are NEXT_PUBLIC_ variables secret?
No. Next.js puts NEXT_PUBLIC_ values into the JavaScript sent to the browser. Variables without that prefix stay on the server.
Is my Supabase anon key a leak?
No. It's meant to be public. It's only safe if Row Level Security is on, with sensible policies, for every table. The service_role or sb_secret_ key is the one that must never ship.
I deleted the key from my code. Am I safe now?
Not yet. Anyone who loaded your site before the change could have copied it. Make a new key, keep it on the server, and delete the old one.
Can I hide the key by splitting it up or encoding it?
No. If the browser can rebuild the key to use it, anyone can. Only code on a server keeps it secret.
Does minifying or obfuscating my JavaScript help?
No. The key is still a plain string in the bundle, and a search finds it.
How do I know if my live app has a secret key in it right now?
Do the 2-minute check on this page, or scan your app free with PatchPaste. It searches the JavaScript your site sends to visitors for Stripe, OpenAI, Anthropic, AWS, GitHub and Supabase admin keys, and shows any it finds masked.
If the leaked value is an OpenAI key, follow the revoke-then-move steps in OpenAI API key in the frontend.
Check your app before you share the link
Paste your URL. We read the JavaScript your site sends to every visitor and flag Stripe, OpenAI, Anthropic, AWS, GitHub and Supabase admin keys (shown masked). We also check for open Supabase tables, exposed files and missing headers. No login, no code access, and the report is free.
Want to see one first? View a sample report.