Materialized Views in API in Supabase
Supabase security checks · MEDIUM
A materialized view is reachable through the API, and row level security doesn't apply to it.
What goes wrong
Postgres materialized views cannot have row level security (RLS) policies. If one is in the public schema of your Supabase project, it is fully accessible through the API.
How it happens
The materialized view was created in the public schema, which the API exposes.
How to find it
List the materialized views in the public schema.
SELECT n.nspname AS schema, c.relname AS matview_name FROM pg_class c JOIN pg_namespace n ON c.relnamespace = n.oid WHERE c.relkind = 'm' AND n.nspname = 'public';
How to fix it
Move it to a schema the API doesn’t expose, or restrict access with column-level privileges.
ALTER MATERIALIZED VIEW public.<matview_name> SET SCHEMA private;
Check your own project
Locksoup runs these checks on your Supabase database in about a minute, with a read-only role, and gives you the SQL to fix what it finds.