Unslop

Your Lovable app is exposing an API key. What to do in the next hour

How to tell if a key in your Lovable app is public by design or a real leak, how to rotate it, and how to move the call to the server.

Updated

Short answer: if the key is your Supabase anon or publishable key, it is meant to be public and is safe only when RLS is on. If it is any other secret key (Stripe secret, OpenAI, Supabase service role or secret key), treat it as stolen: rotate it now, then move the call to the server.

Step 1: work out which kind of key it is

  • Public by design: Supabase anon key or sb_publishable_… key, Stripe pk_… publishable key. These are fine in the browser.
  • Must stay secret: Supabase service_role key or sb_secret_… key, Stripe sk_… or rk_… keys, OpenAI sk-… keys, any email, SMS or payment provider secret.

To check what your live app ships, open it, press F12, go to the Sources tab and search the JavaScript for sk_, sk-, service_role and secret.

Step 2: rotate the key right now

Deleting the key from your code is not enough. It is already in old builds, browser caches and possibly your Git history. Go to the provider's dashboard, create a new key and revoke the old one. Then check that provider's usage or billing page for activity you do not recognise.

Step 3: move the call to the server

Anything in a Vite app that starts with VITE_, or is written directly in a source file, ends up in the browser. The fix is to make the secret call from code that runs on a server. In a Lovable + Supabase app the simplest place is a Supabase Edge Function:

  1. Store the new key as a secret: supabase secrets set OPENAI_API_KEY=… (or in the dashboard under Edge Functions → Secrets).
  2. Write an Edge Function that reads it with Deno.env.get("OPENAI_API_KEY") and makes the call.
  3. Have your app call the function with supabase.functions.invoke(…) instead of calling the provider directly.
  4. Inside the function, check the user is logged in before doing anything that costs money.

Step 4: make sure it does not come back

  • Search your GitHub repository for the old key. If it is in history, it is still public. Rotation is what protects you.
  • Turn on GitHub secret scanning for the repository.
  • When you prompt Lovable for a feature that uses a paid API, ask for it to go through an Edge Function.