Demo, all content is generated
Question

Is it bad that my Supabase key is visible in my Lovable app's JavaScript?

Solved · 3401 views · asked by mariam_k · edited

A friend who works in IT opened devtools on my app (appointment booking for my physio practice) and found the Supabase URL and a long key in the JS file. He said that's a security issue. Lovable says it's fine. Who is right?? It has patient names and phone numbers.

What I’ve tried

Asked Lovable to "hide the key", it moved it to an env variable, but my friend says it's still visible in the built file.

Comment
The key is not the question here. The question is what someone can do with it. Do you know if RLS is enabled on your tables? lena_ops · edited
there is a green shield icon next to most tables? not all mariam_k · edited
Thanks for asking this publicly. Had the same question and was too embarrassed to ask. chen_wei · edited

3 answers

Marked as helpful by the asker
mira_dev · edited

Both are partly right.

The anon/publishable key is meant to be public. Every Supabase frontend ships it, moving it to an env var doesn't hide it (Vite bakes VITE_ vars into the bundle). Lovable is right about that.

But your friend is right to worry, because that key lets anyone call your database as an anonymous user. The only thing between that key and your patient data is Row Level Security.

Do this today:

  1. Dashboard → Table Editor: every table must show RLS enabled. "Not all" is the problem.
  2. For each table, check the policies. Things like using (true) for select on a table with patient data = public.
  3. Test it: log out, open the console, run await supabase.from('appointments').select('*'). You should get [].
  4. Run Supabase's Security Advisor (Advisors → Security), it flags tables without RLS.

The service_role key is the one that must never be in the frontend. Search your built JS for service_role to be sure.

Comment
2 tables had no RLS, one of them was appointments. Turned it on and added policies, logged out test gives [] now. Feeling a bit sick honestly. mariam_k · edited
Good that you found it now. Consider checking the Supabase logs for unexpected reads in the last weeks, and depending on your country you may have a reporting duty for health data. mira_dev · edited
Excellent answer, nothing to add except: repeat step 3 every time you add a table. lena_ops · edited
amir_h · edited

One more check people miss: Storage buckets. If you upload referral letters or anything, make sure the bucket is not public and has policies too. Same logic as tables.

Comment
chidi_eze · edited

If the service_role key was ever in the frontend, or pasted into a chat with an AI tool, rotate it. Settings → API. Takes a minute.

Comment