Vite · Next.js · Lovable · Bolt · Expo
Are your API keys exposed in your JavaScript bundle?
Which keys are safe in the browser (Supabase anon, Stripe publishable, Firebase config) and which must never ship (service_role, Stripe secret, OpenAI, Anthropic, Resend). How to check a live site and fix it.
Safe in the browser vs. never in the browser
- Safe by design: Supabase anon/publishable key (protected by RLS), Stripe publishable key pk_live_ / pk_test_, Firebase web config (protected by security rules), public analytics IDs.
- Never: Supabase service_role / sb_secret_ keys, Stripe sk_live_ / rk_live_, OpenAI sk-proj-…, Anthropic sk-ant-…, Resend re_…, SendGrid SG.…, GitHub tokens, AWS secret keys, any private key.
How keys end up in the bundle
An AI builder needs a value in the frontend, so it adds a VITE_ or NEXT_PUBLIC_ variable. The app works. The key is now public. The same happens when a fetch to OpenAI is written in a React component instead of a server function.
npm run build
grep -rEo "sk_live_[0-9a-zA-Z]{10}|sk-proj-[A-Za-z0-9_-]{10}|sk-ant-[a-z0-9]+-[A-Za-z0-9_-]{10}|sb_secret_[A-Za-z0-9_-]{10}|service_role" dist/ .next/static/ 2>/dev/nullFix
- Rotate the exposed key at the provider first: removing it from code doesn't un-publish old deployments.
- Move the call into a server route or Edge Function that reads the key from a non-public environment variable.
- Rate-limit that route per user, especially if it calls a paid AI API.
Check it yourself
Run the free exposure check on your live URL. It reads your page and the scripts it loads, exactly as a browser does, and reports known secret formats redacted.
Check what your app exposes (free, 30 seconds)
Questions
Can I hide a key with obfuscation or base64?
No. Anything the browser can use, a person can read. The only fix is to keep the key on a server.
Is my Supabase anon key a problem?
Not by itself. It's public by design; check your Row Level Security policies instead.
Updated 18 November 2026 · by Psychevus