LeakOwl
How it worksWhat we checkPricingSign inScan free

Guide

How to hide API keys in a Lovable app

And how to check they aren't already leaked. Plain steps you can paste into Lovable.

Not sure if your Lovable app is leaking a key right now? LeakOwl watches your live app for keys in JS bundles, Supabase tables with RLS off, and exposed .env files. Run the free teaser scan at leakowl.com.

Short answer: you can't hide a secret key in frontend code. Everything Lovable ships to the browser (React code, JS bundles, environment variables prefixed VITE_) can be read by anyone who opens DevTools. To keep a key secret, store it as a Supabase secret and call the outside API from a Supabase Edge Function. Your app calls the function, never the API directly.

1. Know which keys are fine to show

KeySafe in frontend?Why
Supabase anon / publishable keyYesIt's meant to be public. Row Level Security (RLS) is what protects your data.
Supabase service_role / secret keyNoBypasses RLS. Anyone with it can read and write every table.
Stripe publishable key (pk_live_…)YesMeant for the browser.
Stripe secret key (sk_live_…)NoCan issue refunds, read customers, create charges.
OpenAI / Anthropic / Gemini / ElevenLabs keysNoAnyone can copy it and run up your bill.
Google Maps browser keyOnly if restrictedRestrict it to your domain and set a daily quota.

If a "No" key is in your frontend, assume it's already been copied.

2. Move the secret key into a Supabase secret

  1. In Supabase, open Project Settings → Edge Functions → Secrets (or ask Lovable to "add a Supabase secret named OPENAI_API_KEY").
  2. Paste the key there. Don't put it in chat prompts, code files, or a VITE_ variable.
  3. Delete any copy of the key from your code and from .env files that are committed to GitHub.

3. Call the API from an Edge Function

Prompt you can paste into Lovable:

Create a Supabase Edge Function called ai-proxy that reads OPENAI_API_KEY from Deno.env, checks the user is logged in using the Authorization header, applies a simple per-user rate limit, and forwards the request to OpenAI. Update the frontend to call this function with supabase.functions.invoke instead of calling OpenAI directly. Remove every reference to the OpenAI key from frontend code.

Minimal shape of the function:

// supabase/functions/ai-proxy/index.ts
Deno.serve(async (req) => {
  const auth = req.headers.get("Authorization");
  if (!auth) return new Response("Unauthorized", { status: 401 });
  const body = await req.json();
  const r = await fetch("https://api.openai.com/v1/chat/completions", {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${Deno.env.get("OPENAI_API_KEY")}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify(body),
  });
  return new Response(await r.text(), {
    status: r.status,
    headers: { "Content-Type": "application/json" },
  });
});

4. Rotate any key that was ever exposed

Deleting a key from code doesn't revoke it. Old builds, Git history, and anyone who already copied it still have it.

  1. Create a new key in the provider dashboard (OpenAI, Stripe, Supabase, etc.).
  2. Put the new key in Supabase secrets.
  3. Revoke the old key.
  4. Set a spend limit or usage cap on the new key.

Supabase tip: rotate in a quiet window and update every place that uses the key (Edge Functions, Vercel env vars, CI). Rotating without updating them takes the app down.

5. Check your live app

  • Open your published app, press F12 → Sources (or Network), and search the JS for sk_, sk-, service_role, AIza, and secret.
  • Visit https://yourapp.com/.env. It should return 404.
  • Open the app logged out in a private window. If you can see other users' data, RLS is off or too loose.
  • In Supabase, open Advisors → Security Advisor and fix every "RLS disabled" warning.

FAQ

Is the Supabase anon key in my Lovable app a leak?

No. It's designed to be public. The risk is tables without RLS policies.

Can I hide a key with .env in Lovable?

Only server-side. Any VITE_ variable is bundled into the browser code.

My AI bill spiked. What now?

Revoke the key immediately, create a new one with a spend cap, move it behind an Edge Function, then ask the provider about a refund.

Want a heads-up next time a key slips into your build?

LeakOwl re-checks your live app and alerts you. Free teaser scan at leakowl.com.

Scan my app free
TermsPrivacyAcceptable usesupport@leakowl.com
© 2026 LeakOwl. LeakOwl checks what anyone can see from outside. It is not a full security test. It cannot promise your app is safe.