Deutsch
Security wikiSecrets

What is an environment variable?

Also known as: env var, .env file, VITE_ variable, import.meta.env, Deno.env

Environment variables hold configuration outside your code. Why VITE_ variables end up in the browser, where secrets belong instead, and how to check your app.

By Tim GeithnerPublished 2 min read

Short answer

An environment variable is a named value, such as an API key or URL, that a program reads from its environment instead of from its source code. In a Vite or Lovable app, every variable that starts with VITE_ is copied into the JavaScript that visitors download, so it is public. Secrets belong in server-side secrets, such as Supabase Edge Function secrets, and never in a VITE_ variable.

Ask an AI about this page:ChatGPTClaude

On this page

An environment variable is a named value that a program reads from the environment it runs in, instead of having it written into the source code. URLs, feature flags and API keys are typical examples. The idea is that the same code runs in development and production with different values, and that secrets stay out of the repository.

Environment variables in an AI-built app

Lovable, Bolt and most React apps use Vite, and Vite has one rule that matters more than any other here: variables that start with VITE_ are exposed to your client code through import.meta.env, and their values “are bundled into your source code at build time”, as the Vite docs put it. Vite’s docs say plainly that VITE_* variables should not contain sensitive information such as API keys.

So there are two very different places a value can live:

WhereExampleWho can read it
VITE_ variable in the frontendVITE_SUPABASE_PUBLISHABLE_KEYEvery visitor, in the downloaded JavaScript
Server-side secretEdge Function secret OPENAI_API_KEY, read with Deno.env.getOnly your server code

The classic mistake: the AI tool needs an OpenAI or Stripe secret key “in the app”, adds VITE_OPENAI_API_KEY to .env, and calls the API straight from the browser. It works, and the key is now public. Supabase’s docs also warn that the legacy JWT secret leaks easily through VITE_ or NEXT_PUBLIC_ variables.

How to check your app

  1. List every VITE_ variable in .env, .env.* and your hosting settings. For each one ask: would I be fine with this value on a billboard? Supabase URL and publishable key: yes. Anything with secret, service, sk_ or sb_secret_: no.
  2. Build the app and search the output folder (dist/) for the start of each secret you own, for example sk_live, sk_test or sb_secret_.
  3. Check that .env and *.local files are in .gitignore, and search your git history for keys that were committed earlier.
  4. In edge functions, check that values read with Deno.env.get are never returned in a response or written to logs.

How to fix or prevent it

Move the secret to the server: store it as an Edge Function secret (supabase secrets set NAME=value), call the third-party API from an edge function, and let the browser call that function instead. Then treat the old key as leaked and rotate it, because every visitor could already copy it. The step-by-step fix is on Secret key in a VITE_ variable, and which keys may live in the frontend at all is explained in API keys in AI-built apps.

Frequently asked questions

Is a value in .env secret because .env is not committed?

Only if your code never sends it to the browser. In a Vite app, any VITE_ value is written into the built JavaScript, whether .env is in git or not.

Which values may safely be VITE_ variables?

Values that are public by design: your Supabase URL, the Supabase publishable or anon key, a Stripe publishable key, an analytics ID. Nothing that starts with sk_, sb_secret_ or is called a secret or service key.

Are environment variables on the server a safe place for secrets?

They are the common and accepted option when no secrets manager is available. OWASP notes they can leak through logs, crash dumps and child processes, so never print them or return them in responses.

Sources

  1. 1.Env Variables and Modes — Vite
  2. 2.Environment variables (secrets) — Supabase Docs
  3. 3.Secrets Management Cheat Sheet — OWASP Cheat Sheet Series
  4. 4.Understanding API keys — Supabase Docs

Find this in your own app

ShipRely reads your repository (read-only), proves each finding with file and line, and gives you a fix prompt to paste into your AI builder.

Run a demo audit
  • Read-only access to your repository
  • Every finding with file and line
  • Fix prompts for Lovable, Cursor, Claude Code and Bolt