Lovable, Bolt, Cursor and Replit are good at making an app work. They are less careful about where a secret key ends up. If the app calls a paid service straight from the browser, the key has to be in the browser too. Anyone can read it there. I checked the facts below against the official docs in November 2026.
Short answer: some keys are meant to be public, and some must never be. Open your live site and search its JavaScript for secret key prefixes. Search your GitHub repo and its history too. If a secret key shows up, replace it at the provider first, then check the logs, then move the call to a server function.
Why AI-built apps leak keys
Everything your app sends to the browser is public. A builder that puts an API call in the frontend puts the key there as well. Two common setups make this easy to do by accident:
- Vite (a common build tool for web apps). Its env docs say: "
VITE_*variables should not contain sensitive information such as API keys." They add that the values "are bundled into your source code at build time." - Next.js. Its environment variables guide says a variable with the
NEXT_PUBLIC_prefix is inlined into the JavaScript bundle at build time, and that it "will be inlined into any JavaScript sent to the browser."
So a secret named VITE_STRIPE_SECRET_KEY or NEXT_PUBLIC_OPENAI_KEY is not secret. The prefix is what puts it in the browser.
The other common leak is the repo. A .env file committed to GitHub is leaked, even if you delete it in the next commit. It stays in the git history. Vite's docs say to add *.local to your .gitignore, and the Next.js docs warn: "You almost never want to commit these files to your repository."
Keys that may be public, and keys that never may
May be public, when set up right:
- Supabase publishable key (
sb_publishable_), or the olderanonkey. Supabase's API keys page says the publishable key is "Safe to expose online: web page, mobile or desktop app, GitHub actions, CLIs, source code." This is only safe if Row Level Security is on and has real policies. See the database security checks. - Firebase web API key. Firebase's docs say keys for Firebase services "are OK to include in code or checked-in config files." The same page says it is critical to apply API restrictions to these keys, and that covered APIs are protected by Firebase App Check, not by keeping the key secret. Your Security Rules still decide who can read your data.
- Stripe publishable key (
pk_live_,pk_test_). Stripe's keys page says it can't perform sensitive operations such as creating charges or reading account data, and you can include it in front-end code.
Never public:
- Supabase secret key (
sb_secret_) and the olderservice_rolekey. Supabase says: "A secret key bypasses every Row Level Security policy you have." It belongs in backend code only. - Stripe secret key (
sk_live_,sk_test_) and restricted keys (rk_live_,rk_test_). Stripe's table marks both as not safe to expose. Webhook signing secrets are separate from API keys and just as private. Stripe's page says they let your receiver "authenticate that webhooks actually came from Stripe." - Email provider keys (Resend, SendGrid, Postmark), database connection strings, and AI provider keys. I could not point to one doc page for all of these, so the rule is simple: if the key lets someone spend money, send mail or read data as you, keep it on the server.
Check your own app in 15 minutes
- Search the live site. Open your app in Chrome, open DevTools and go to the Sources tab. Look through the loaded JavaScript files for the prefixes
sk_live,sk_test,rk_live,sb_secret,service_roleandsk-. Any hit on a secret prefix is a problem. A hit onpk_orsb_publishableis fine. - Look at the Network tab. Use the app, then look for requests that go straight from the browser to a paid service, such as an AI provider or an email API. If the browser sends the key itself, so can anyone else.
- Search the repo. Look for
.envfiles that are tracked, and search the history withgit log -p -S"sk_live". It lists every commit that added or removed that text. Repeat for your other prefixes. - Turn on GitHub secret scanning. GitHub's docs say it scans the full Git history of all branches for hardcoded credentials, and that on public repositories it "runs automatically for free." For private repositories the page says organization-owned ones need GitHub Secret Protection. It does not say the same for private repos owned by a normal user account, so check your own settings page.
- Know about push protection. Push protection is "designed to prevent hardcoded credentials, such as secrets or tokens, from ever being pushed to your repository." The docs say the user-level version is on by default and stops you pushing secrets to public repositories.
- Run a scanner on your repo. Gitleaks describes itself as a tool to "Find secrets" and scans a repo and its history with
gitleaks git path_to_repo. TruffleHog says it can "Find, verify, and analyze leaked credentials." A clean report does not prove the repo is clean. Treat it as one more check.
If your app is on Lovable or Bolt and you plan to move it, this is a good moment to sort public from secret. See moving your app to your own GitHub and hosting.
If a secret leaked
Work in this order.
- Replace the key first. GitHub's guide on removing sensitive data says: "as a first step you need to revoke and/or rotate that secret." Deleting the file does not help while the old key still works.
- Stripe: rotating a key revokes it and creates a replacement. The Dashboard has a grace period of up to 7 days where both keys work, so you can switch without downtime. If you choose "Now", the old key is deleted. For a leaked key, I would not wait. Stripe's best practices say to rotate "immediately even if you aren't sure anyone saw it."
- Supabase: creating new keys does not revoke legacy ones. The old keys stay valid until you disable them in the dashboard, which is a separate step. Supabase says: "Rotate a leaked key as soon as you fix the cause of the leak." Supabase's new secret keys don't work from a browser, but its docs add that "an attacker can still use the key from other tools", so a leaked one still needs replacing. Follow Supabase's guide for rotating a leaked key, since it changes with their key system.
- Other providers: revoke the key in their dashboard and create a new one.
- Check the logs and your bill. Stripe lets you open the request logs for any key. For other providers, look at usage and billing for the days the key was exposed. Look for calls you do not recognise.
- Remove it from the code. Put the new key in the host's environment settings only.
- Then think about the git history. GitHub says that once the secret is rotated, rewriting history "may not be warranted." It also says that if you rewrite and force push, the commits may still be accessible in forks and other people's clones. A rotated key is what protects you, not the rewrite.
- Move the call to the server. The browser should call your own function, and the function calls the paid service. Supabase Edge Functions, Netlify Functions and Vercel Functions all work. For example, Supabase Edge Functions read secrets you set in the dashboard or with
supabase secrets set. Add a check in the function so only signed-in users can call it, and so one user cannot call it a thousand times. See also stopping fake sign-ups. If the browser then reports "blocked by CORS policy", the function needs CORS headers: see the CORS fix.
I left out provider spending limits. They differ per provider and I did not verify each one. Look in the billing settings of the service you use.
Prevention
- Put
.envand*.localin.gitignorebefore the first commit. - Keep secrets in your host's environment settings. Stripe's docs say: "Don't put keys in source code or configuration files checked into version control."
- Never use
VITE_orNEXT_PUBLIC_on a secret. - Use a restricted Stripe key where you can. Stripe says it limits the damage if the key is exposed.
- Keep GitHub secret scanning and push protection on.
- Do the 15-minute check before each launch. It fits into the launch-ready checklist.
How I do it in my own app
In WuXing Zodiac (wuxingzodiac.me, the app that sells personal PDF readings), the AI key and the Stripe secret key are only read inside Netlify Functions. I searched the built browser files on November 10, 2026, and found neither.
Prompts for your AI tool
A vague "make it secure" makes the tool rewrite things you did not ask about. Name the key, the file and what must not change.
- "The app calls the email API from browser code. Move that call into a server function (a Netlify Function or Supabase Edge Function). The key must be read from an environment variable on the server and must never appear in browser code. Keep the UI exactly the same."
- "Search the whole project for any variable starting with VITE_ or NEXT_PUBLIC_ that holds a secret key, and list them. Don't change anything yet."
- "Add .env and *.local to .gitignore and tell me whether any env file is currently tracked by git."
The tool may tell you it moved the key when it only renamed it. Run the browser search from the checklist below to confirm.
Checklist
- No
sk_,rk_,sb_secretorservice_rolein the live site's JavaScript. - No paid API called straight from the browser with a key.
- No
.envfile tracked in git, and none in the history. - Secrets exist only in the host's environment settings.
- Supabase tables have Row Level Security on. Firebase rules are not set to
if true. - GitHub secret scanning and push protection are on.
- You know where each key lives and how to replace it. For a handover, see what to give a developer who takes over your app.
Want this fixed for you?
I finish and fix apps built with Lovable, Bolt, Cursor or Replit, including finding exposed keys and moving them to the server. Or send me the details and I'll reply within 24 hours.