How to check if your Lovable, Bolt, Cursor or v0 app leaked an API key in the JavaScript (and how to fix it)
LaunchGuard is a weekly health check for the app you shipped from Lovable, Cursor, Bolt, or v0. The first scan is free and shows your 1–2 most severe findings with a fix prompt; paid plans add the full report, every fix prompt, weekly rescans and an emailed report. Everything below you can do yourself in your browser and dashboards, for free. Only test an app you own.
TL;DR
- A value that ends up in your frontend JavaScript is public. Vite copies any
VITE_variable into the client bundle at build time and says those values should not contain API keys. (Vite: Env Variables and Modes) Next.js inlinesNEXT_PUBLIC_values into the JavaScript sent to the browser the same way. (Next.js: Environment Variables) - Some keys are meant to be public: a Stripe publishable key (
pk_...), a Supabase publishable or legacyanonkey, and a Firebase-provisioned web API key that is restricted to Firebase services. (Stripe: API keys; Supabase: API keys; Firebase: API keys) Secret keys are not: an OpenAI secret, a Stripe secret or restricted key (sk_.../rk_...), a Supabase secret or legacyservice_rolekey (sb_secret_...), a Resend API key, or a Gemini Developer API key. (OpenAI: API key safety; Stripe: API keys; Supabase: API keys; Lovable: Secrets; Firebase: API keys) - Check the JavaScript your live site actually serves, not only your git repo. If a secret was ever in a published bundle, rotate it at the provider, then move the call to a server or Edge Function and keep the new key out of any
VITE_orNEXT_PUBLIC_variable.
Why this happens
Lovable, Bolt and v0 apps are usually a frontend that talks to APIs. When you publish, that frontend is bundled into JavaScript files every visitor can download.
In Vite, variables prefixed with VITE_ "will be exposed in client-side source code after Vite bundling." Vite's own warning is: "VITE_* variables should not contain sensitive information such as API keys." For production secrets it points you to "a backend server or serverless/edge functions." (Vite)
In Next.js, used by v0 and by Cursor projects that are on Next.js, a NEXT_PUBLIC_ prefix tells the framework to inline the value into the client bundle at next build. Non-prefixed variables stay in the server environment. (Next.js)
Lovable draws the same line. Secrets (for example STRIPE_SECRET_KEY, RESEND_API_KEY, OPENAI_API_KEY) are "injected into your Edge Functions automatically, and never reach the browser." Anything prefixed with VITE_ is a "build-time, browser-exposed value" that belongs in .env, and only if it is safe to be public, such as VITE_SUPABASE_URL or VITE_SUPABASE_PUBLISHABLE_KEY. Lovable also warns you not to gitignore .env in a Lovable project, because the build needs those VITE_* values. A secret in that file is therefore in the repo as well as in the bundle. (Lovable: Secrets)
A repo scanner that only looks at git will miss a key that was injected at build time from an environment variable and never committed. That is why you also search the live JavaScript.
What is safe in the frontend, and what is not
| You found | Public by design? | Source |
|---|---|---|
Stripe publishable key, pk_test_... or pk_live_... |
Yes. Stripe says you can include it in front-end code. It cannot create charges or read account data. | Stripe: API keys |
Stripe secret key sk_... or restricted key rk_... |
No. | Stripe: API keys |
Supabase publishable key sb_publishable_... or legacy anon key |
Yes. It "only reaches what Row Level Security allows." | Supabase: API keys |
Supabase secret key sb_secret_... or legacy service_role key |
No. It "bypasses Row Level Security" and "must never leave your control." | Supabase: API keys |
| Firebase web API key, restricted to Firebase services | Yes, when it is used only for Firebase services and your Security Rules (and App Check, where you use it) are in place. Firebase says these keys "do not need to be treated as secrets." | Firebase: API keys |
Gemini Developer API key (Generative Language API) |
No. Firebase: it "should never be included in your code or configuration files." | Firebase: API keys |
| OpenAI API key | No. OpenAI: "Never deploy your key in client-side environments like browsers or mobile apps." | OpenAI: API key safety |
| Resend or other provider secrets Lovable lists as backend-only | No. | Lovable: Secrets |
A public key can still be a problem if something else is wrong. A Supabase publishable key is only safe when Row Level Security is actually protecting your tables. That is a separate check: How to check if your Lovable or Supabase app has RLS disabled (and fix it). A Firebase web key is only safe when Security Rules restrict the data.
Step 1 — Search the JavaScript your live site serves
Do this only against an app you own.
- Open the published site in a private window.
- Open DevTools (usually F12 or right-click → Inspect).
- Go to Sources (Chrome or Edge) or Debugger (Firefox). Open the page's
.jsfiles, or use the search-in-all-files box. - Also try View Page Source and search the HTML, in case a key was written into a script tag.
Search for these strings, one at a time:
sb_secret_andservice_role(Supabase secret / legacy service role key)sk_live,sk_test,rk_live,rk_test(Stripe secret or restricted keys; apk_hit is the publishable key and is expected)OPENAI_API_KEY,STRIPE_SECRET_KEY,RESEND_API_KEY- a short, unique prefix of any other secret you issued (your OpenAI key, a Gemini Developer API key, and similar). Do not paste the full key into a public thread. Stripe's secret prefix is
sk_with an underscore; a publishablepk_hit is expected and is not a leak. VITE_andNEXT_PUBLIC_followed by names that look like secrets (VITE_OPENAI_API_KEY,NEXT_PUBLIC_OPENAI_API_KEY,VITE_SUPABASE_SERVICE_ROLE_KEY, and similar)
If you maintain the project locally, also search the built output after a production build (often dist/, .next/, or build/), and search the repo:
# current files — adjust the pattern to the prefixes above
git grep -nE "sb_secret_|service_role|sk_live|sk_test|rk_live|rk_test|OPENAI_API_KEY|STRIPE_SECRET_KEY|RESEND_API_KEY"
# history, in case a key was committed and later deleted
git log --all -p -G "sb_secret_|service_role|sk_live|OPENAI_API_KEY" | head
A hit under supabase/functions/ or in a server route, reading the key from the function's secrets or a non-public environment variable, is the usual safe place. A hit under src/, in a React/Vue file, in a committed .env, or in a downloaded .js file from your live site, is a leak.
Step 2 — Rotate the leaked key first
Once a secret has been in a published JavaScript file, treat it as public. Removing it from the code is not enough: copies can already be in browsers, CDNs and archives.
- OpenAI: Rotate the key from the API Keys page. OpenAI also recommends monthly spend limits with hard enforcement, because a leaked key can lead to unexpected charges. (OpenAI: API key safety)
- Stripe: Roll or expire the leaked secret or restricted key on the API keys page in the Dashboard, and start using the new key only on a server you control. (Stripe: API keys)
- Supabase: Create a new secret key, put it only in server or Edge Function secrets, then delete or disable the exposed one. For a leaked legacy
service_roleJWT, follow Supabase's rotation steps in the API keys guide. Supabase notes that a secret key used from a normal browser can be rejected with HTTP 401, but "an attacker can still use the key from other tools." (Supabase: API keys) - Lovable-managed
LOVABLE_API_KEY: Use Rotate in More → Settings → Secrets if you think that key was exposed. (Lovable: Secrets) - Any other provider: Create a new key, switch the server to it, then revoke the old one.
Do not put the replacement key in a VITE_ or NEXT_PUBLIC_ variable, in frontend source, or in a Lovable .env file.
Step 3 — Move the call to a server or Edge Function
The frontend should call your own function. The function should call the provider. The key should live only in that function's secrets.
On Lovable, that means a project secret plus an Edge Function. Lovable injects secrets into Edge Functions and does not include them in frontend code. Reserved SUPABASE_ names, including SUPABASE_SERVICE_ROLE_KEY, are already available to those functions as Deno.env.get("SUPABASE_SERVICE_ROLE_KEY"). You do not need to add them as VITE_ variables. (Lovable: Secrets)
On your own Supabase project, put provider keys in Edge Function secrets and read them inside the function, not in browser code. (Supabase: API keys)
On v0 or a Next.js app from Cursor, add the secret as a server-only environment variable (no NEXT_PUBLIC_ prefix) and call the provider from a Route Handler, Server Action or other server code. (Next.js)
On a Vite app, including Lovable and any Bolt or Cursor project that uses import.meta.env.VITE_*, keep secrets on a backend or Edge Function, not in VITE_ variables. (Vite)
Moving the key is not the whole fix. A function that only forwards whatever the browser sends is a stand-in for the key: anyone can call it and you still pay. Before you ship it:
- Check that the caller is a signed-in user (or another check that fits your app).
- Accept only the operations your app needs, not free-form access to any model, amount or recipient.
- Rate-limit per user.
- Set a spend cap at the provider. OpenAI documents monthly spend limits with hard enforcement for this class of risk. (OpenAI: API key safety)
Then rebuild, republish, and repeat Step 1 on the live site to confirm the old value is gone from the JavaScript.
Copy-paste fix prompt for Lovable or Cursor
Audit my project for secret keys that could reach the browser.
1. Search frontend source, committed .env files, and the production JavaScript bundle
for secret values and names, including: sb_secret_, service_role,
sk_live, sk_test, rk_live, rk_test, OPENAI_API_KEY, STRIPE_SECRET_KEY,
RESEND_API_KEY, and any VITE_ or NEXT_PUBLIC_ variable whose name looks like a secret.
2. List every hit and say whether it is in frontend code, a public env var, or server-only code.
Do not print full key values; show only a short prefix.
3. For each real secret in the frontend or in a VITE_ / NEXT_PUBLIC_ variable:
explain how to rotate it at the provider, move the call into an Edge Function
or server route, and store the new key in server-side secrets (Lovable Secrets,
Supabase Edge Function secrets, or a non-public environment variable).
4. Make sure the function checks that the caller is signed in (or another
equivalent check), accepts only the operations this app needs, and is rate-limited.
5. Leave public-by-design values in the client: Stripe pk_ keys, the Supabase
publishable or anon key, and a Firebase web API key used only for Firebase services.
6. After the change, tell me how to re-check the live JavaScript so I can confirm
the secret is gone.
Do not commit a new secret, and do not put any replacement key in a VITE_ or
NEXT_PUBLIC_ variable. Show me the plan before you apply it.
FAQ
My repo scanner said there were no secrets. Am I safe? Not necessarily. Vite and Next.js substitute VITE_ and NEXT_PUBLIC_ values at build time, so the live .js file can contain a key that never appeared in git. Search the published JavaScript (Step 1). (Vite; Next.js)
Is it a problem that my Supabase anon or publishable key is in the frontend? No. That key is designed to be public. The problem is a secret or service_role key in the frontend, or tables without real Row Level Security. (Supabase: API keys)
Lovable asked me for an API key in the chat. Is that the leak? Not by itself. Lovable's docs say it prompts you through a secure input, saves the value as a project secret, and injects secrets only into Edge Functions. The leak is if the generated frontend code, or a VITE_ variable, then uses that key. Read the code it wrote, and still do Step 1 on the published site. (Lovable: Secrets)
I removed the key from the code yesterday. Can I keep the old key? No. If it was in a published bundle or a repo, rotate it. OpenAI, Stripe and Supabase all treat a leaked key as compromised until it is revoked or replaced. (OpenAI; Stripe; Supabase)
I switched stacks from Next.js to Vite and reused the same env-var habit. In Next.js, only NEXT_PUBLIC_ values are inlined into the browser. In Vite, the public prefix is VITE_. A secret named VITE_OPENAI_API_KEY is public by definition. (Vite; Next.js)
Sources
- Vite docs — Env Variables and Modes: https://vite.dev/guide/env-and-mode
- Next.js docs — Environment Variables: https://nextjs.org/docs/app/guides/environment-variables
- Lovable docs — Secrets: https://docs.lovable.dev/features/secrets
- Supabase docs — API keys: https://supabase.com/docs/guides/getting-started/api-keys
- Stripe docs — API keys: https://docs.stripe.com/keys
- OpenAI Help Center — Best practices for API key safety: https://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety
- Firebase docs — API keys: https://firebase.google.com/docs/projects/api-keys
- Related LaunchGuard guide — How to check if your Lovable or Supabase app has RLS disabled (and fix it): https://getlaunchguard.app/guides/check-supabase-rls-disabled-lovable-app
- Related LaunchGuard guide — Lovable site not showing up on Google? How to check what Googlebot actually sees: https://getlaunchguard.app/guides/lovable-site-not-showing-on-google-check-what-googlebot-sees
Last checked against the sources above: 24 November 2026.