How to find and fix leaked API keys in a Lovable, Bolt or Cursor app (Stripe, OpenAI, Supabase)
Published · Updated · Last verified · VibeCPR
sk_live_ or restricted rk_live_, OpenAI sk-, Supabase sb_secret_ or service_role) is in your app's JavaScript or git history, treat it as stolen. Rotate it at the provider first (Stripe: Developers → API keys → ⋯ → Rotate key, expiration Now), then move the call into a server or edge function that reads the new key from a server-only secret, redeploy, and search the live bundle again. Deleting the key from your code does not un-leak it. Only Stripe's publishable pk_ key and Supabase's publishable/anon key are meant to be public.Short answer: if a secret key is visible in your app’s JavaScript or anywhere in your git history, rotate it at the provider first, then fix the code. For Stripe that’s Developers → API keys → ⋯ → Rotate key, expiration Now. Then move the call into a server or edge function, store the new key as a server-only secret, redeploy, and search the live bundle again. Stripe’s own guidance: “If a restricted or secret API key is exposed or compromised, rotate it immediately even if you aren’t sure anyone saw it” (Stripe docs).
Jump to: Leaked a Stripe key? · Which keys are safe in the browser · Find leaks · Rotate · Lovable and Bolt secrets · GitHub push protection · What we verified · FAQ
Why AI-built apps leak keys
AI app builders optimize for “it works.” The fastest way to make a Stripe or OpenAI call work is to paste the key right where the call happens, often in a React component that ships to every visitor’s browser.
Frameworks make this easy to do by accident. Vite’s docs say variables prefixed with VITE_ “will be exposed in client-side source code after Vite bundling” and “should not contain sensitive information such as API keys” (Vite docs). Next.js inlines anything prefixed NEXT_PUBLIC_ “into any JavaScript sent to the browser” (Next.js docs). Rename STRIPE_SECRET_KEY to VITE_STRIPE_SECRET_KEY to “fix” an undefined error, and you’ve published it. We checked this today: in a Vite 8.4.0 build, a fake sk_live_ value in a VITE_ variable showed up in the shipped JS file, and the same kind of value in a plain STRIPE_SECRET_KEY variable did not.
The cost is real. One founder’s AI-built app exposed a live Stripe secret key; 175 customers were charged $500 each and he lost about $2,500 in Stripe fees. Escape’s research counted 400+ leaked secrets across 1.4K vibe-coded apps.
Leaked a Stripe secret key? Do this first
- Check the mode. Live keys start
sk_live_/rk_live_; sandbox keys contain_test_. Stripe keeps sandbox and live keys separate, and sandbox keys can’t reach live data, so a test key is less urgent. Rotate it anyway. - Rotate the key. Stripe Dashboard → Developers → API keys → the ⋯ menu next to the key → Rotate key. Choose an Expiration. Stripe’s docs: with a future time, “both the old and new keys work for up to 7 days”; “If you choose Now, the old key is deleted.” For a key that was in your live site or a public repo, choose Now.
- Copy the new key once. In live mode you can’t reveal a secret or restricted key you created again later (Stripe docs).
- Put it where the browser can’t see it.
- Lovable: ask Lovable to update your Stripe key. That opens the Update Stripe secret key form, and the key is stored as the backend secret
STRIPE_SECRET_KEY. Never paste the key into the chat (Lovable Stripe docs). - Bolt: database icon → Secrets, using the exact name your server function reads (Bolt docs).
- Supabase Edge Functions: Edge Function secrets in the Supabase dashboard.
- Next.js / Vercel: a server-only env var (no
NEXT_PUBLIC_).
- Lovable: ask Lovable to update your Stripe key. That opens the Update Stripe secret key form, and the key is stored as the backend secret
- Delete the old variable and redeploy, e.g.
VITE_STRIPE_SECRET_KEYin.envor your host’s settings, then repeat the live-bundle search. Onlypk_should come back. - Check what the old key did. ⋯ → View request logs opens Workbench for that key. Also scan recent payments, refunds, new customers and webhook endpoints for anything you didn’t do.
- Next time, use a restricted key. Stripe recommends restricted keys (
rk_) with only the permissions a component needs over full-access secret keys. Lovable’s Stripe form accepts one. A restricted key limits the damage of a leak; it is not safe to expose.
Stripe also says that if it detects an exposed secret or restricted key, it notifies you and “in some cases” deactivates it, but it “doesn’t guarantee detection of all exposed or compromised keys” (Stripe docs). Don’t wait for that email.
Which keys are safe in the browser and which aren’t?
| Key | Looks like | Safe in frontend? | Notes |
|---|---|---|---|
| Stripe publishable | pk_live_… / pk_test_… | Yes | Stripe: “You can include it in front-end code” |
| Stripe secret | sk_live_… / sk_test_… | No | Full access to your Stripe account |
| Stripe restricted | rk_live_… / rk_test_… | No | Limited to its permissions, still server-only |
| Stripe webhook signing secret | whsec_… | No | Not an API key, but it’s what proves webhooks come from Stripe |
| Supabase publishable / legacy anon | sb_publishable_… / JWT eyJ… with "role":"anon" | Yes, if RLS is on for every table | The public key only reaches what RLS allows |
| Supabase secret / legacy service_role | sb_secret_… / JWT with "role":"service_role" | Never | Bypasses all Row Level Security |
| OpenAI / Anthropic / Gemini keys | sk-… and others | No | Anyone can spend your credits |
| Resend, SendGrid, Twilio keys | various | No | Can send email/SMS as you |
Supabase’s API keys docs are blunt about the secret key: “A secret key bypasses every Row Level Security policy you have. Never put one in a browser, a shipped application, or source control.” OpenAI’s key safety guide says the same: “Never deploy your key in client-side environments like browsers or mobile apps.”
Tip: a legacy Supabase key is a JWT starting with eyJ. Paste it into a JWT decoder and look at the role field: anon is the public key; service_role is the master key.
Step 1: Find leaked keys in your live app (5 minutes, no tools)
Only check apps you own.
- Open your published site (not the editor preview) in Chrome and press F12.
- Click through the app first: log in, open the main screens, trigger checkout and the AI feature. Many apps load code in chunks, so a key used on the billing page may only appear after you visit it.
- Press Ctrl+Shift+F (Cmd+Option+F on Mac) to search all loaded files.
- Search for each of:
sk_live,rk_live,sk_test,sk-,sb_secret,service_role,whsec_,eyJ,api_key,apiKey,secret,Bearer. - In the Network tab, click any request that goes straight to
api.stripe.com,api.openai.comor a similar API. AnAuthorizationheader there means the key is in the browser. - For each hit, check it against the table above. Anything from a “No” row is leaked.
Also try https://your-app.com/.env, /.env.local and /.git/config. The real file contents must not come back. (Many single-page apps answer every unknown URL with the home page and a 200; that’s harmless. What matters is whether KEY=value lines or a [core] section appear.)
Prefer a scanner? Download the built files and scan them. If you have the code, run npm run build and point gitleaks at the output: gitleaks dir dist -v (Next.js: .next/static). In our test it flagged a fake sk_live_ key in a Vite bundle.
Step 2: Find leaked keys in your code and git history
Deleting a key from your code doesn’t remove it from git history. Anyone who can see the repo can still find it.
# scan the current files
gitleaks dir . -v
# scan every commit ever made
gitleaks git . -v
# find the commits that added or removed a specific string
git log --oneline -S "sk_live_"
In our test repo, a key committed and then deleted in the next commit was invisible to gitleaks dir and found by gitleaks git and git log -S. If your repo is or ever was public on GitHub, treat anything in history as already leaked.
Step 3: Rotate the key first, then clean up
Order matters. GitHub’s guidance for a leaked secret: “as a first step you need to revoke and/or rotate that secret” (GitHub Docs). Once it’s revoked, rewriting history is optional.
- Stripe: see the Stripe steps above.
- OpenAI: revoke the key and create a new one. OpenAI recommends project keys with an expiration date and monthly spend limits with hard enforcement: “Spend alerts alone don’t stop API traffic” (OpenAI).
- Supabase: Supabase’s rotation guide says to fix the cause first, then create a new secret key (Settings → API Keys), switch every server component to it, and only then delete the compromised secret key, or deactivate the legacy keys if it was
service_role. Retiring the legacy keys turns off the legacyanonkey too, so move your frontend to the publishable key first. Creating new keys doesn’t revoke the legacy ones, and deleting a secret key can’t be undone. If someone is actively abusing the key, retire it immediately. If your Lovable app then shows “Invalid API key”, see Lovable “Invalid API key” after rotating Supabase keys. - Lovable’s built-in AI key:
LOVABLE_API_KEYhas a Rotate action in Secrets (Lovable docs).
Then check each provider’s logs for the window when the key was exposed.
Step 4: Move the call to the server
The new key should live only where visitors can’t see it:
- Lovable: secrets live under More → Settings → Secrets and are injected into Edge Functions only. Lovable says they “never reach the browser” and are write-only once saved (Lovable Secrets docs). Lovable rejects
VITE_-prefixed names in Secrets, becauseVITE_values are build-time browser values that belong in.env. Don’t gitignore.envin a Lovable project: Lovable says it needs.envcommitted for builds. Keep only publicVITE_values (Supabase URL, publishable key) in it. - Bolt: database icon → Secrets. Bolt’s docs: “Secrets only work with server functions,” and Bolt never writes the value into your files, browser code or published site. Values in Bolt’s
.envthat browser code reads are sent to every visitor (Bolt docs). - Next.js (Cursor, v0, Claude Code): keep the key in an env var without
NEXT_PUBLIC_, and call the provider from a Route Handler or Server Action. - Vite (Cursor, Replit, exported Lovable/Bolt apps): keep the key without the
VITE_prefix and call the provider from a serverless function (Vercel/Netlify functions or a Supabase Edge Function).
Copy-paste prompt for your AI tool:
Security fix: the [Stripe/OpenAI/...] secret key must never reach the browser.
1. Remove every use of the key from client components and from any VITE_ or NEXT_PUBLIC_ variable.
2. Create a server-side endpoint (edge function / server function / route handler) that makes the API call,
reads the key from a server-only secret, and checks the user is logged in.
3. Update the frontend to call that endpoint instead.
4. Make sure no secret values are in .env or any committed file. (Lovable: keep .env committed,
but only with public VITE_ values. Other projects: add .env* to .gitignore.)
Show me the diff before applying.
Step 5: Make sure it never happens again
- GitHub push protection. Push protection blocks a push that contains a known secret format before it reaches the repo. For your personal account it is on by default and “stops you from pushing secrets to public repositories” (Settings → Code security → Push protection for yourself). Push protection for a repository needs GitHub Secret Protection enabled (repo Settings → Advanced Security). Anyone with write access can bypass a block by giving a reason, which creates an alert (GitHub Docs).
- GitHub secret scanning. On public repos it “runs automatically for free,” scans the entire git history, and sends known partner secrets to the provider so they can act (GitHub Docs). Organization-owned private repos need GitHub Secret Protection (Team or Enterprise Cloud). Private repos on a personal account don’t get it on GitHub.com unless you’re on Enterprise Cloud with Managed Users, so run gitleaks yourself.
- gitleaks as a pre-commit hook and in CI. A pre-commit hook alone is easy to skip: AI agents blocked by one sometimes retry with
git commit --no-verify. See AI agent pushed API keys to GitHub? git commit —no-verify skipped your pre-commit hook. - Restricted keys and limits. Stripe restricted keys with the fewest permissions; Stripe access policies to limit where a key can be used from; OpenAI project keys with expirations and hard spend limits. See your AI bill spiked: rate limits and spend caps.
- One line in your AI tool’s rules: “Never put secret keys in client code, VITE_/NEXT_PUBLIC_ variables or committed files.”
- Re-scan after every big AI-generated change.
Related: keys in agent config files (Stripe sk_live in an MCP config, Claude Code settings.local.json); moving Stripe calls server-side breaks webhooks? Fix “No signatures found matching the expected signature for payload”; the server now uses Supabase’s secret key? Read RLS not working because the server uses the service_role key. On Firebase? Fix “Your Cloud Firestore database has insecure rules”.
What we verified
- Tested locally (Nov 30, 2026; fake keys only;
research/leaked-keys-test/run.sh, outputrun.out.txt): Vite 8.4.0 build: aVITE_STRIPE_SECRET_KEYvalue appeared in the shipped JS and a plainSTRIPE_SECRET_KEYvalue did not. gitleaks 8.30.1diron the build output: 1 leak found. A key committed and then removed in the next commit:gitleaks dirfound nothing,gitleaks gitfound 1 leak, andgit log -Slisted both commits. - Docs-based, not tested (fetched Nov 30, 2026, list in
research/keys-and-vercel-404-refresh-2026-11-30.md): Stripe’s key types, rotation (7-day overlap, Now, live keys shown once), request logs, restricted keys, proactive detection; Lovable and Bolt secrets locations and behaviour; Supabase rotation steps; OpenAI spend limits; GitHub secret scanning and push protection availability. We didn’t rotate a real Stripe, OpenAI or Supabase key, use a Lovable or Bolt account, or push to GitHub. - Our reading, not documented: that AI builders often paste keys into components or
VITE_variables; the search-term list.
FAQ
I leaked my Stripe secret key in my Bolt or Lovable app. What do I do?
Rotate it now: Stripe Dashboard → Developers → API keys → ⋯ next to the key → Rotate key, and pick expiration Now if it was in your live site or a public repo (Stripe otherwise keeps the old key working for up to 7 days). Copy the new key once, because live-mode keys can't be revealed again. Put it in the server-side secret store (Lovable: ask Lovable to update your Stripe key, which opens the Update Stripe secret key form; Bolt: database icon → Secrets), make sure no VITE_ variable or React component still uses it, redeploy, and search the live JavaScript again. Then open the old key's ⋯ → View request logs and check payments, refunds and customers for anything you didn't do.
How do I find leaked API keys in my vibe-coded app?
Two places: what the browser downloads and your git history. Open the live site, click through every page, and search all loaded files in Chrome DevTools (Ctrl+Shift+F, or Cmd+Option+F on Mac) for sk_live, rk_live, sk-, sb_secret, service_role, whsec_ and eyJ. Then run gitleaks dir . on your code and gitleaks git . on the whole history. Anything in a VITE_ or NEXT_PUBLIC_ variable is in the bundle by design.
Is a Stripe restricted key (rk_live_) safe to put in frontend code?
No. Stripe's key table marks restricted keys as not safe to expose, the same as secret sk_ keys. A restricted key can only do what its permissions allow, which limits the damage, but anyone who copies it from your bundle gets those permissions. Only the publishable pk_ key belongs in the browser.
Will rotating my Stripe key break checkout?
Only if you choose to expire the old key right away. Stripe's rotation dialog lets you set an expiration: with a future time, the old and new keys both work for up to 7 days; with Now, the old key is deleted immediately. For a key that was public, pick Now and accept a few minutes of broken checkout while you update your server secret.
I deleted the key from my code. Am I safe?
No. It is still in your git history, in every clone and fork, and in any build already deployed. In our test, gitleaks found nothing in the current files after the key was removed but found it in history. Rotate the key; once it is revoked, rewriting history is optional.
Will GitHub warn me if I commit an API key?
On public repositories, yes: GitHub's secret scanning runs automatically for free, scans the whole history, and reports known partner secrets to the provider. Push protection for users is on by default and stops you pushing secrets to public repositories. Private repositories owned by an organization need GitHub Secret Protection (Team or Enterprise Cloud), and private repositories on a personal account don't get secret scanning on GitHub.com unless you're on Enterprise Cloud with Managed Users, so run gitleaks yourself there.
Is my Supabase anon or publishable key a leak?
No. The publishable key (sb_publishable_) and the legacy anon key are designed to be public; Row Level Security decides what they can reach. The secret key (sb_secret_) and the legacy service_role key bypass RLS and must never be in a browser, an app you ship, or source control.
How do I know if someone used my leaked key?
Check the provider's logs for the time the key was exposed. Stripe: the key's ⋯ menu → View request logs, plus recent payments, refunds and customers. OpenAI: usage for the project. Supabase: API and database logs and unexpected rows. Stripe also says it may notify you, or deactivate a key, if it detects one exposed, but it doesn't guarantee detection.
Get Patch Notes
One email a week: breaking changes and security fixes for apps built with AI. Also puts you on the waitlist for the free Vibe Check.