cd /news/ai-tools/are-vite-environment-variables-secre… · home › topics › ai-tools › article
[ARTICLE · art-156662] src=dev.to ↗ pub= topic=ai-tools verified=true sentiment=· neutral

Are VITE_ environment variables secret? No, and here's how keys leak from Lovable and Bolt apps

A developer published a guide explaining that Vite's VITE_-prefixed environment variables are embedded into client-side JavaScript bundles at build time and are therefore publicly readable, with the same applying to Next.js's NEXT_PUBLIC_ and Create React App's REACT_APP_ prefixes. The writeup details how secret keys leak from AI-built apps such as Lovable, Bolt and Cursor frontends, lists which key types are safe to expose (Supabase publishable keys with Row Level Security, Stripe pk_ keys, PostHog phc_ keys) versus which must stay server-side (OpenAI sk-proj-, Anthropic sk-ant-, Supabase sb_secret_, Stripe sk_live_), and recommends moving secret-key calls into Supabase Edge Functions using supabase secrets set.

by read2 min views2 publishedOct 24, 2026

Short answer: no. In a Vite app, every environment variable that starts with VITE_ is written into your JavaScript bundle at build time. That bundle is downloaded by every visitor, so anyone can read the value in DevTools.

The same is true of NEXT_PUBLIC_ in Next.js and REACT_APP_ in Create React App.

Vite hides variables without the VITE_ prefix from your frontend code on purpose. The prefix is how you tell Vite "this value is safe to publish".

Here's how secret keys usually end up public in AI-built apps:

import.meta.env.OPENAI_API_KEY. undefined in the browser, so the feature breaks.VITE_OPENAI_API_KEY. Lovable, Bolt and most Cursor-built frontends are Vite apps, so this comes up a lot.

VITE_ variable sb_publishable_) key, as long as Row Level Security is on for every table pk_live_, pk_test_) phc_, Sentry DSNs) sk-proj-), Anthropic ( sk-ant-), Groq, Replicate sk_live_) and webhook secrets ( whsec_) sb_secret_ key, which bypasses RLS entirelyre_, SendGrid SG.), AWS keys, database URLs with a password Not sure which kind a key is? I made a free key checker that tells you what a key is and whether it's allowed in the browser. It runs entirely client-side, so the key never leaves the page.

supabase secrets set OPENAI_API_KEY=.... A prompt that works in Lovable, Bolt or Cursor:

Move every call that uses a secret API key out of the frontend into a
Supabase Edge Function that reads the key from Supabase secrets. Remove
the VITE_ variable for it and call the function instead. Only allow
logged-in users to call it. Don't print any keys in your reply.

Your .env file isn't what matters. What matters is what ended up in the built JavaScript. Two ways to check:

sk-, sk_live, service_role and .env files, source maps and missing headers. The full version of this guide, with a FAQ, is here.

── more in #ai-tools 4 stories · sorted by recency
── more on @vite 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/are-vite-environment…] indexed:0 read:2min 2026-10-24 · —