Secrets
A VITE_ variable bundles a secret into the client
Cataloged October 16, 2026 · Lovable · Bolt · Cursor
Symptom
An API key works in the browser preview. Anyone who opens the built JavaScript can read it.
Root cause
Vite's env guide says variables prefixed with VITE_ are exposed in client source after bundling, statically replaced at build time. Variables without that prefix are not exposed. The same page says VITE_ variables must not contain API keys or other secrets, and that production secrets belong in a backend or an edge function. This card applies when the generated app is a Vite client. The value is in the bundle even if the UI never displays it.
Before and after
Vite documents that the VITE_ prefix publishes the value into the client bundle. The after name is read only on the server.
Before
VITE_SERVICE_ROLE_KEY
After
SERVICE_ROLE_KEY
Fix prompt
In this Vite project only: 1. Find every VITE_ variable whose value is a secret (API keys, service role keys, webhook secrets, database URLs). 2. Rename them so they are not prefixed with VITE_, and read them only in server code or an edge function. 3. Leave VITE_ only on values that are safe to publish, such as a public site URL or a publishable Supabase key. 4. Rebuild and confirm the secret string is gone from the dist JavaScript. Do not paste the secret values into the chat.
Paste this into the coding tool that has your own project open.
2-minute self-check
These steps are for an app you own. Do not run them against someone else's project.
- In your own project, open .env files and list every name that starts with VITE_.
- Build your own app and search the output JavaScript for a secret value you recognize. It should not be there.
- If it is there, rotate that credential after you remove the VITE_ prefix and redeploy.
Common questions
The API key works in the Vite preview. Why can a visitor read it?
Vite's env guide says variables prefixed with VITE_ are exposed in client source after bundling, statically replaced at build time. Variables without that prefix are not exposed. VITE_ variables must not contain API keys or other secrets. The value is in the bundle even if the UI never displays it.
What should stay prefixed with VITE_?
Only values that are safe to publish, such as a public site URL or a publishable Supabase key. Rename secrets so they are not prefixed with VITE_, read them in server code or an edge function, rebuild, and search your own dist JavaScript. Do not paste the secret into chat.
Longer guide
- Lovable blocked your publish: what each critical finding means and how to fix it
What the November 23 security-check redesign changed, when the workspace setting blocks every publish path, and how to read the finding on a project you own.
- OpenAI API key exposed in the frontend: check your own app
Which keys are meant to be public, why a NEXT_PUBLIC_ or VITE_ prefix ships the others, and what to do on your own app if a secret key is in the bundle or the git history.