Lovable app exposed API key: how to find and fix it
Short answer
Anything in your Lovable app's frontend runs in the visitor's browser, so any key there is public. The Supabase publishable/anon key is designed for that, but keys for OpenAI, Stripe secret keys, Resend, or Supabase's service_role/secret key are not. Move them into Lovable's Secrets, call the third-party API from a server-side function, and rotate any key that was ever shipped.
The fix
- Rotate first-party and third-party keys that appeared in code or git history, in each provider's dashboard.
- Store the new key in Secrets, not in the chat or source. Lovable's docs describe detecting pasted keys and guiding you to Secrets.
- Call the API from a server-side function and have the frontend call that function. A Supabase Edge Function example:
// supabase/functions/generate/index.ts
Deno.serve(async (req) => {
// 1. Verify the caller (e.g. check the user's JWT with supabase.auth.getUser)
// 2. Validate input and apply your own rate limit
const r = await fetch('https://api.example.com/v1/generate', {
method: 'POST',
headers: { Authorization: `Bearer ${Deno.env.get('EXAMPLE_API_KEY')}` },
body: JSON.stringify(await req.json()),
})
return new Response(await r.text(), { status: r.status })
})
An unauthenticated proxy just moves the problem: anyone can then spend your API credits through it. Check the user first.
How to check
- Run Lovable's built-in Quick scan and Deep scan from the Security view; the Deep scan covers leaked secrets and unauthenticated endpoints.
- Search the project for
sk-,sk_live_,re_,service_role,sb_secret_andVITE_variables holding secrets (Vite ships everyVITE_variable to the browser). - Open your published site, view the JS bundle in DevTools, and search for the same strings.
Why it matters
In our own review of 30 public Lovable and Bolt repos built on Supabase, 33% had at least one critical or high-severity issue (small sample, directional only). Leaked keys and over-broad database access were the recurring themes. Lovable's docs also say its scans help but don't replace a security review.
Check your own project in seconds
Upload a .zip of your own Lovable, Bolt, Cursor, Supabase or Firebase project. ProdCanary reviews the code statically and shows your top 3 risks with plain-English fixes. Your upload is deleted right after the scan.
Run a free scanFAQ
Is the Supabase anon key in my Lovable app a leak?
No. It's meant to be public. Your RLS policies are what protect the data behind it.
I deleted the key from the code. Is that enough?
No. Rotate it. Old builds, forks and git history may still contain it.
Does Lovable fix this automatically?
Lovable detects pasted keys and runs security scans, but you're still responsible for reviewing the result, per Lovable's own docs.
Sources
This guide is for securing apps you own or are authorised to work on. Facts above are from the official docs linked; check them for changes.