Supabase and Firebase: open database rules in vibe-coded apps
Contents
Supabase and Firebase are popular with AI app builders for good reason: authentication, database and storage are ready in minutes, without your own server. The price is an unusual security model. There is no backend of your own between the browser and the database; the database itself decides, row by row, who may do what. If the generated app skips that step, the database is effectively public.
Why is the anon key not the problem?
Many developers are alarmed when they find the Supabase key in the browser. That key is meant to be there. Supabase describes its publishable key (formerly the anon key) as safe to expose, because it only reaches what Row Level Security allows (Supabase API keys). Firebase says the same about its API keys: they may be in code, and protection comes from the rules (Firebase API keys).
The flip side: the key cannot protect anything. Supabase recommends enabling RLS on every table in an exposed schema and notes that a new table in the public schema starts with privileges for the anon, authenticated and service_role roles (Supabase, Row Level Security). Without RLS, those privileges are the only check. The truly dangerous key is the secret key (formerly service_role): it bypasses RLS and must never be used in a browser.
What happens when RLS is missing?
In spring 2025, a security researcher scanned apps from the Lovable showcase and reported 303 endpoints in 170 of 1,645 analysed projects with missing or inadequate RLS. According to his statement, exposed data included email addresses, names, phone numbers, payment information and API keys; on one site the researchers were able to write a record marked as paid without going through the payment provider (Matt Palmer, statement on CVE-2025-48757). The case was published as CVE-2025-48757; Lovable disputes the entry and states that customers are responsible for protecting their application's data. For you as the operator, that is the key point: the rules are your job.
What are the typical mistakes in Supabase projects?
- RLS switched off. The table is reachable through the API with the public key. Supabase's database linter reports this as rls_disabled_in_public (lint 0013).
- A policy with using (true). RLS is on, but the policy lets every caller read every row. It silences the warning without protecting anything.
- "Logged in" instead of "owner". A policy for the authenticated role without a condition lets any registered user read all rows, and sign-up is usually open to everyone.
- Missing with check. A policy restricts reading, but users can insert or update rows with someone else's user_id, or change their own role column to admin.
- Views that bypass RLS. Views created by the database owner run with the owner's rights by default. In Postgres 15 and later, create them with security_invoker = true so that the caller's policies apply.
- Public storage buckets. Files in a public bucket can be downloaded by anyone who knows the path; use private buckets with policies for personal documents.
How do you secure Supabase tables with RLS?
First, find tables without RLS. In the SQL editor:
select schemaname, tablename
from pg_tables
where schemaname = 'public' and rowsecurity = false;
Then enable RLS and write one policy per operation that ties the row to its owner. The example assumes a table notes with a column user_id:
alter table public.notes enable row level security;
create policy "notes_select_own" on public.notes
for select to authenticated
using ((select auth.uid()) = user_id);
create policy "notes_insert_own" on public.notes
for insert to authenticated
with check ((select auth.uid()) = user_id);
create policy "notes_update_own" on public.notes
for update to authenticated
using ((select auth.uid()) = user_id)
with check ((select auth.uid()) = user_id);
auth.uid() returns the ID of the requesting user and is null when nobody is signed in; wrapping it in select lets Postgres evaluate it once per statement instead of once per row, as the Supabase documentation recommends. Columns that only your system may set, such as roles, plans or payment status, belong in a separate table that users cannot write, or are changed only by a server function with the secret key.
How do you secure Firebase with Security Rules?
When you create a database or storage bucket, Firebase offers "locked mode" or "test mode"; test mode grants access to everyone. Google warns that once an app is deployed it is on the internet, and that without authentication and rules anyone who guesses the project ID can steal, modify or delete data (Firebase, avoid insecure rules). Test mode rules are time-limited, so apps often keep working until the date passes and then someone "fixes" them by opening everything permanently.
A rule set that ties each user document to its owner:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read, write: if request.auth != null && request.auth.uid == userId;
}
}
}
Avoid rules like allow read, write: if true and allow read, write: if request.auth != null for the whole database; Firebase calls the latter not suitable for production, because every signed-in user can then read everything. Apply the same discipline to Cloud Storage rules.
How do you test your own rules safely?
Test only your own project. The simplest check imitates an anonymous visitor: call the Supabase REST API with nothing but the public key.
curl "https://YOUR-PROJECT.supabase.co/rest/v1/notes?select=*&limit=5" \
-H "apikey: YOUR_PUBLISHABLE_KEY"
An empty list or an error is the expected result for private data; real rows mean the table is open. Repeat the test while logged in as user A and try to read user B's rows. In Firebase, use the Rules Playground in the console or the local emulator to run the same scenarios. Also check the Security Advisor in the Supabase dashboard after every schema change, and ask your AI tool to add RLS and policies to every migration it writes.
Frequently asked questions
Do I need RLS if my app has a login?
Yes. The login only proves who the user is. Without RLS, the public key still gives direct access to the tables, with or without a login in the user interface.
Is the service_role key safe in a server function?
Yes, as long as it stays on the server: in an edge function, a serverless function or your backend, loaded from an environment variable. It must never appear in client code, in a VITE_ or NEXT_PUBLIC_ variable or in a repository. More on this in API keys and secrets in the frontend.
Can athorion check my Supabase or Firebase rules?
No. athorion's free check is passive and non-intrusive and never sends requests against your database API. What it does see from outside: open database ports on servers you run yourself (for example a self-hosted Postgres on port 5432), TLS certificates, security headers, disclosed versions with known CVEs and subdomains. The attack surface analysis explains this external view in detail.
Next steps
Open database rules are point three of ten in our guide to vibe coding security. Before going live, work through the pre-launch security checklist, and check what your domain shows to the internet with the free external check.
Sources
Researched and structured with AI assistance, reviewed for accuracy by Robin Schwarzfeld.