Field notes Field note 16
Supabase RLS checklist for Lovable and AI-built apps
A Supabase Row Level Security checklist for apps built with Lovable or Bolt: policies per table, exposed keys, storage buckets, and the second-user test.
· 11 min read
A Supabase app is only as private as its Row Level Security. Check that RLS is on for every table the API exposes, each operation has a policy that checks auth.uid(), no secret or service_role key reaches the browser, views and security definer functions are locked down, storage buckets are private unless they must be public, Edge Functions verify the caller, and the Security Advisor is clean. Then run the test that settles it: sign up as a second user and try to read the first user's rows through the API.
This matters because apps built with Lovable, Bolt and similar tools often talk to Supabase straight from the browser, with a key anyone can read. That key is meant to be public. What protects your customers' data is the database rules behind it. If those rules are missing or too loose, any visitor or signed-in user can read or change records that are not theirs, whatever the front end hides.
Checked on 2026-11-04 against: Supabase documentation (Row Level Security, Securing your API, API keys, Storage, Edge Functions, Database advisors) and Supabase's database linter. Dashboard labels and defaults change, so confirm them in your own project.
The checklist at a glance
| Check | What goes wrong if you skip it | How to test |
|---|---|---|
| RLS on every exposed table | Anyone with the public key reads and writes the table | SQL query below, or Security Advisor |
| Grants trimmed | Signed-out visitors keep insert or delete rights | has_table_privilege query |
| One policy per operation | A user edits or deletes other users' rows | Second-user test on each operation |
auth.uid() used correctly | Policies trust data the user can edit | Read every policy |
| No secret key in the browser | Every rule is bypassed | Search the built JavaScript |
| Views and functions locked down | A view or function hands out every row | Security Advisor, view options |
| Storage buckets scoped | Files readable or listable by anyone | Try a file URL signed out |
| Edge Functions check the caller | A function returns all users' data | Call it with another user's token |
| Second-user test | You don't actually know | Two accounts, direct API calls |
1. Is RLS enabled on every table in an exposed schema?
Yes, including "internal" tables. Supabase's guide says a table in an exposed schema without RLS is readable and writable by any role with a grant on it. "Exposed" means reachable through the Data API: public by default, plus any schema listed under exposed schemas in your API settings.
This SQL Editor query lists tables in public with RLS off, using the same check as Supabase's database linter:
select n.nspname as schema, c.relname as table_name
from pg_catalog.pg_class c
join pg_catalog.pg_namespace n on n.oid = c.relnamespace
where c.relkind = 'r'
and n.nspname = 'public' -- add any other schema you expose
and not c.relrowsecurity;
Fix each one:
alter table public.invoices enable row level security;
Once RLS is on, the table returns nothing through the API with a publishable key until you add policies (Row Level Security guide), so parts of the app may go blank until step 3 is done. That is the safe failure.
2. Are the grants trimmed to what each role needs?
Grants decide which operations are allowed; policies decide which rows. On existing projects, Supabase says a new table in public [starts with every privilege granted to anon, authenticated and service_role](https://supabase.com/docs/guides/database/postgres/row-level-security), and policies do not take those grants back. Newer projects may differ; check yours.
select has_table_privilege('anon', 'public.invoices', 'insert,update,delete') as anon_can_write;
If signed-out visitors should get nothing, revoke and grant back only what the app uses:
revoke all on table public.invoices from anon, authenticated;
grant select, insert, update, delete on table public.invoices to authenticated;
Securing your API shows how to stop new tables getting these grants automatically.
3. Does every table have a policy per operation?
Write a separate policy for select, insert, update and delete, each naming its role with to. Supabase recommends this over a for all policy, which hides which operation each rule was meant to cover. The two clauses do different jobs:
- **
using** filters which existing rows the user can see, update or delete. - **
with check** decides what a new or changed row may look like.
For a table where each user owns their rows:
create policy "Owners read their invoices"
on public.invoices for select
to authenticated
using ( (select auth.uid()) = user_id );
create policy "Owners create their invoices"
on public.invoices for insert
to authenticated
with check ( (select auth.uid()) = user_id );
create policy "Owners update their invoices"
on public.invoices for update
to authenticated
using ( (select auth.uid()) = user_id )
with check ( (select auth.uid()) = user_id );
create policy "Owners delete their invoices"
on public.invoices for delete
to authenticated
using ( (select auth.uid()) = user_id );
The with check on update is the easiest line to miss. Supabase's guide says it [stops a user from reassigning user_id to someone else](https://supabase.com/docs/guides/database/postgres/row-level-security). An update also needs a matching select policy to work.
Watch for policies that are always true. Supabase's linter flags unconditional using (true) or with check (true) on insert, update or delete as [rls_policy_always_true](https://github.com/supabase/splinter/blob/main/splinter.sql), and leaves select policies out because using (true) there is a common way to publish public data. Use it for a select policy only when the table really is public.
4. Are the auth.uid() patterns right?
auth.uid() returns the ID of the signed-in user making the request. Four rules from the Supabase guide:
- **Wrap it in
select.**(select auth.uid())lets Postgres evaluate it once per statement instead of once per row: same rule, faster on large tables. Index the column it compares against (user_idhere). - **It returns
nullfor signed-out requests.**null = user_idis never true, so the row is hidden, but make the intent explicit withto authenticatedorauth.uid() is not null. - **Never authorize on
user_metadata.** Users can edit their ownraw_user_meta_data, so a policy that reads a role from it lets anyone make themselves admin. Store roles inapp_metadataor in a table only admins can write. The linter checks for this: [rls_references_user_metadata](https://github.com/supabase/splinter/blob/main/splinter.sql). - Team access goes through a membership table, not a column the user can set. For shared records, the policy checks that a row exists in
team_membersfor(select auth.uid()).
5. Do you know the difference between anon and authenticated?
Every API request runs as one of two roles: with the publishable key, anon when nobody is signed in and authenticated when a user is (API keys page). Two traps:
- "Authenticated" is not "trusted". Anyone can usually sign up, so
to authenticated using (true)lets every stranger with an account see every row. It is a common mistake, and the second-user test catches it. - **Supabase anonymous sign-ins use the
authenticatedrole**, notanon. They can be told apart by the [is_anonymousclaim in the JWT](https://supabase.com/docs/guides/database/postgres/row-level-security); decide whether your policies should exclude them.
6. Is the secret or service_role key kept out of the browser?
It must be. The secret key (and the legacy service_role key) bypasses every Row Level Security policy, so one leak exposes the whole database. How to check:
- Environment variable names. Anything with a client prefix ends up in the bundle: Vite exposes
VITE_variables to client code, and Next.js inlinesNEXT_PUBLIC_ones into browser JavaScript. Never give the secret key such a prefix. - The live JavaScript. In DevTools, Sources, search all files for
sb_secret_(the new-style secret key prefix) andservice_role. Legacy keys are long JWTs starting witheyJ; the publicanonone is expected, but if you find a second, decode its middle part and check whether its role isservice_role. Supabase says it plans to deprecate the legacyanonandservice_rolekeys by the end of 2026, so expect to move to publishable and secret keys. - Git history. A key committed once is leaked even if deleted later. Rotate it in Settings, API Keys.
Supabase answers a new-style secret key sent from a browser with a 401, based on the User-Agent header, but says this does not stop other tools. Treat it as a safety net: a leaked key still needs rotating.
7. Do views and security definer functions respect RLS?
Often not, by default. Supabase's guide says views bypass RLS by default because they run with their creator's rights, usually postgres, so a view over a protected table can hand out every row. On Postgres 15 and above, create views with security_invoker:
create view public.my_invoices
with (security_invoker = true)
as select id, amount_due, status from public.invoices;
security definer functions run as their owner too, so they skip RLS. They are useful inside policies (for membership checks), but one placed in an exposed schema is callable over the Data API with the creator's privileges. Put them in a private schema, pin set search_path = '', and revoke execute from public. The linter flags [security_definer_view, function_search_path_mutable and security definer functions executable by anon or authenticated](https://github.com/supabase/splinter/blob/main/splinter.sql).
8. Are storage buckets public only when they should be?
Buckets are private by default. A public one bypasses access controls for retrieving and serving files: anyone with the URL can open the file. Right for logos, wrong for invoices or ID scans. Uploading, deleting, moving and copying still need access control either way.
Private buckets are controlled by RLS policies on storage.objects. A pattern from Supabase's storage access control guide keeps each user to a folder named after their ID:
create policy "Users upload to their own folder"
on storage.objects for insert
to authenticated
with check (
bucket_id = 'documents' and
(storage.foldername(name))[1] = (select auth.jwt()->>'sub')
);
Add matching select, update and delete policies, then open a file URL in a private window, signed out. A broad select policy on a public bucket is not needed for URL access and lets clients list every file; the linter calls this [public_bucket_allows_listing](https://github.com/supabase/splinter/blob/main/splinter.sql).
9. Do Edge Functions check who's calling?
They should. By default verify_jwt is on, and the platform returns a 401 for a missing, malformed or wrongly signed JWT before your code runs. Look in supabase/config.toml for verify_jwt = false. That suits webhooks from outside providers, which have no user token, and is a hole anywhere else. Those functions must authenticate the caller some other way, such as a signature check. Note that Supabase says the check alone does not authenticate a caller who sends only an API key, so a publishable key is not a signed-in user.
The bigger risk is inside the function. The admin (service role) client ignores RLS, and Supabase's Edge Functions auth guide warns that a handler querying a shared table through it without filtering by the caller's ID returns every user's rows. Use the user-scoped client for user requests, and the admin client only for work that has to cross users.
10. What does the Security Advisor say?
Open Advisors, then Security Advisor in the dashboard (Database advisors). It is built on Supabase's open-source linter, splinter, whose checks include rls_disabled_in_public (level ERROR), policy_exists_rls_disabled, rls_enabled_no_policy, auth_users_exposed and the ones named above. Fix every ERROR and read each warning before dismissing it: Supabase notes some findings may be intentional. The advisor finds configuration mistakes; it cannot tell whether a policy matches your business rules. That is the next step.
11. The second-user test: does user B see user A's data?
The app's interface may hide other users' data; the API underneath may not. You run this test yourself, on a test project or a copy, not on live customer records.
- Sign up as user A and create records of every kind, including a file.
- Sign up as user B in a private window.
- In B's window, open DevTools, Network, and click any request to
/rest/v1/. Copy theapikeyheader and theAuthorization: Bearer ...value (B's session token). - Call the API directly for each table, as B:
curl 'https://<PROJECT_REF>.supabase.co/rest/v1/invoices?select=*' \
-H "apikey: <PUBLISHABLE_KEY>" \
-H "Authorization: Bearer <USER_B_ACCESS_TOKEN>"
The URL pattern follows Supabase's REST API guide. What you should see: a JSON array containing only B's rows, or an empty array if B has none. Any of A's rows in the response means the select policy is broken.
- Try writes too: a
PATCHon one of A's rows (?id=eq.<A_ROW_ID>), aDELETE, and aninsertwith A'suser_id. Then confirm as A that nothing changed: a denied update often returns an empty result rather than an error. - Repeat with no
Authorizationheader at all, which runs asanon. Most apps should return nothing. - Open one of A's private file URLs in B's window.
For a permanent version, Supabase recommends pgTAP policy tests per table, run with supabase test db, that act as different users and assert what each can do.
FAQ
Is RLS on by default for new tables?
Only for tables created in the Supabase Dashboard. Supabase says dashboard-created tables have RLS enabled by default, and tables made in the SQL Editor or another tool do not, so run the query in step 1 either way.
Can the Data API reach tables in a schema I have not exposed?
No, the Data API serves the schemas listed under exposed schemas in your API settings. Supabase suggests keeping internal tables and helper functions in schemas that are not exposed.
When to get help
If the second-user test shows other users' data, or you are unsure your policies match who should see what, our security check for Supabase and Lovable apps covers every item above: RLS and grants, keys, storage, Edge Functions, and a re-test with a second account. Book a scoping call and bring the project. If the same app also needs to be found on Google, our note on Lovable SEO covers that side.
Checklist
- RLS enabled on every table in every exposed schema
- Grants revoked from
anonandauthenticated, granted back per need - Separate select, insert, update and delete policies, each with
to - Update policies have both
usingandwith check (select auth.uid())compared to an indexed owner column- No authorization based on
user_metadata - No secret or
service_rolekey in the bundle, env prefixes or git history - Views use
security_invoker;security definerfunctions live outside exposed schemas - Private buckets for private files, with
storage.objectspolicies verify_jwton for user-facing Edge Functions; admin client filtered by caller- Security Advisor shows no ERRORs
- Second-user test passed for reads, writes, signed-out access and files