Security methods #51640
Replies: 4 comments
|
Short answer: on Supabase, RLS is the standard and the only policy layer that runs inside the database itself — but it's not the only security method, and some tables genuinely don't need it. The decision per table: RLS is necessary when the table is reachable by the API keys that ship in your frontend bundle. The Tables that don't need RLS:
The alternatives to RLS (and why they complement, not replace it):
If your app is already done and some tables missed RLS, the highest-value order: (1) list which tables select tablename, policyname, roles
from pg_policies
where schemaname = 'public'
and roles::text in ('{anon}', '{public}', '{authenticated}')
and qual = 'true'; |
|
Yes: for tables in schemas exposed through Supabase's Data API, enable RLS and define policies for the access your app needs. The official RLS guide explicitly recommends RLS for every table in an exposed schema. Table grants and row policies are separate checks; keep only the operations each role needs. I would not classify a table as safe merely because your current frontend does not query it, or because your backend writes it with a service key. If that table remains exposed and client roles still have grants, someone can call the API directly without using your UI. A server-only design can be valid, but it needs an actual access boundary: a non-exposed schema and appropriate grants, plus authorization in the backend. Keep privileged keys entirely server-side. One nuance to the earlier answer: For an already-running app, I would inventory the affected tables and intended operations first, then test changes in staging. Enabling RLS without matching policies can immediately stop ordinary client access, so do not switch it on across production blindly. Test with:
Use ordinary user sessions for those tests; a privileged service connection is not evidence that client policies work. Test both allowed and denied operations. A policy permitting If you share one representative table schema and whether access is browser-to-Supabase or through your own backend, with private data removed, it will be possible to suggest a scoped policy and rollout. I would avoid a generic “allow all authenticated users” policy just to make the existing app pass. |
|
Short answer: yes. For any table in a schema the Data API exposes (by default The alternatives are different ways of making a table not reachable, not ways of skipping protection:
Find your exposed, unprotected tables: select c.relname as table_name,
has_table_privilege('anon', c.oid, 'select') as anon_can_read
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public' and c.relkind = 'r' and not c.relrowsecurity;Any row with alter table public.your_table enable row level security;
create policy "owner reads" on public.your_table
for select to authenticated using ((select auth.uid()) = user_id);Two caveats from the same RLS page:
Check both of those as well as your tables. I wrote up the details here: https://www.guardlayer.io/blog/supabase-row-level-security-complete-guide |
|
RLS is the standard when the client talks to the database directly — which, on Supabase, means the Data API (PostgREST, GraphQL, Three supported shapes, in the order of how much they protect you
How to choose, given what you already have Ask one question: can a client holding the anon key reach this table? Run the check that answers it, per table: select relname as table_name, relrowsecurity as rls_enabled
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where n.nspname = 'public' and c.relkind = 'r'
order by relrowsecurity desc;
-- and what the API roles can actually do:
select table_name, grantee, privilege_type
from information_schema.role_table_grants
where table_schema = 'public'
and grantee in ('anon', 'authenticated')
order by table_name, grantee;
The pattern I would not choose: RLS on "most" tables, decided by whoever noticed. The failure mode of that is a table added in a hurry that is reachable by What this is not: a certification judgment. If you handle regulated data (health, payments, minors), the shape choice is still yours above, but the evidence that the shape holds needs to be a test that fails when the boundary breaks — one per table, per role, per operation — not a policy count in a dashboard. |
Uh oh!
There was an error while loading. Please reload this page.
Hello Supabase,
I am wornderign if RLS for each table is the standard and necessary method to protect data in table?
Or cause some tables are not configured with RLS while the APP is done if you got any alternative ways ?
All reactions