LeakyVibe

Guides · Updated 2026-11-03

Does your Supabase view bypass RLS? How to check and fix it (security_invoker)

Short answer: By default a Postgres view runs with the permissions of the role that created it, not the person querying it. In Supabase that's usually the postgres role, which skips Row Level Security (RLS). So a view in the public schema can hand every row of a protected table to anyone with your public key, even when the table's RLS is set up perfectly. Supabase's Security Advisor flags this as "Security Definer View" (lint 0010, level ERROR). The fix on Postgres 15 and above is one line per view: alter view public.<name> set (security_invoker = true); after that the view follows the RLS policies of the user who queries it.

Does your app have this problem? Free scan, 15 sec, no sign-up

or watch it scan our demo app ▶

Why a view can skip your RLS policies

A view is a saved query that looks like a table. Postgres decides whose permissions apply when the view reads its underlying tables, and the default is the view owner, not the user running the query (PostgreSQL docs, CREATE VIEW: https://www.postgresql.org/docs/current/sql-createview.html).

Supabase's own linter explains why this bites: views are often created by highly privileged roles that can bypass RLS, and any view in the public schema is reachable through your project's API. The result is "a view in the public schema runs with elevated privileges and ignores Row-Level Security, which could expose more data through the API than intended" (Supabase splinter lint 0010, https://github.com/supabase/splinter/blob/main/docs/0010_security_definer_view.md).

This is easy to hit in AI-built apps. A common request is "make a view that joins profiles and orders for the dashboard". The AI writes create view ... as select ..., the dashboard works, and nobody notices the view ignores the policies on profiles and orders.

1. Check the Security Advisor (1 minute)

In the Supabase dashboard, open Advisors > Security Advisor. A view with this problem shows up as "Security Definer View" ("View bypasses row-level security") with level ERROR (lint 0010, https://supabase.com/docs/guides/database/database-advisors). You can also run the same checks from the terminal with supabase db advisors. On Postgres 15 and above, the lint lists views in schemas your API exposes that the anon or authenticated role can read, so every hit is reachable from outside.

2. List your views with SQL

Run this in the SQL Editor. It shows every view in public, whether logged-out (anon) and logged-in (authenticated) users can read it, and its options:

select c.relname as view_name,
  has_table_privilege('anon', c.oid, 'SELECT') as anon_can_read,
  has_table_privilege('authenticated', c.oid, 'SELECT') as logged_in_can_read,
  coalesce(array_to_string(c.reloptions, ', '), '') as options
from pg_class c
join pg_namespace n on n.oid = c.relnamespace
where c.relkind = 'v' and n.nspname = 'public'
order by 1;

Any row where options doesn't include security_invoker=true (or on), and anon_can_read or logged_in_can_read is true, is a view that skips RLS for API users.

3. Test it from the outside

Ask the view for data the same way a stranger would, with only your public (publishable or anon) key, which is visible in your site's JavaScript anyway:

curl 'https://<project-ref>.supabase.co/rest/v1/<view_name>?select=*&limit=5' \
  -H 'apikey: <your publishable or anon key>'

If rows come back that a logged-out visitor shouldn't see, that's the leak. Only test your own project.

4. Fix it: make the view obey RLS

On Postgres 15 and above (current Supabase projects), Supabase's RLS guide says to set security_invoker = true so the view obeys the RLS policies of its underlying tables when anon and authenticated query it (https://supabase.com/docs/guides/database/postgres/row-level-security). For an existing view:

alter view public.<view_name> set (security_invoker = true);

For new views, put it in the definition:

create view public.<view_name>
with (security_invoker = true)
as select ...;

Things to know after the change:

  • The view now returns only the rows the user's RLS policies allow on each underlying table. If the dashboard suddenly shows less, a policy is missing on a table. Add a policy for the rows the user should see; don't turn the view back.
  • The user also needs SELECT permission on the underlying tables, not just on the view (PostgreSQL docs: a security invoker view checks the base tables with the permissions of the user running the query).
  • If the view existed to show some columns of a private table to everyone (for example a public name and avatar from profiles), security_invoker will hide those rows too. Move the public columns to their own table with an open read policy, and keep the private table locked.
  • On older Postgres versions without security_invoker, Supabase's advice is to revoke access to the view from anon and authenticated, or move it to a schema your API doesn't expose.
revoke select on public.<view_name> from anon, authenticated;

5. Don't forget materialized views and functions

Two cousins of the same problem show up in the Security Advisor too: materialized views exposed through the API (lint 0016), which don't follow RLS, and security definer functions that anon or authenticated can run (lints 0028 and 0029). Treat them the same way: if it returns private data, revoke access or move it out of the exposed schema. For a materialized view, Supabase's fix revokes select from public, anon and authenticated (the public role holds a default grant too). For a function that doesn't need to bypass RLS, you can also switch it to security invoker.

revoke select on public.<materialized_view> from public, anon, authenticated;

-- for a function that doesn't need to bypass RLS:
alter function public.<function_name>(<arg types>) security invoker;

Prompt to give your AI coding tool

List every view in the public schema of my Supabase database. For each one, tell me whether it sets security_invoker = true and whether the anon or authenticated role can select from it. For every view that doesn't set security_invoker, write a migration with alter view ... set (security_invoker = true). Then check that each underlying table has RLS enabled and policies that allow exactly the rows the app needs. From now on, every create view you write must include with (security_invoker = true).

Quick checklist

  1. Open Security Advisor and look for "Security Definer View" (lint 0010).
  2. Run the SQL above and list views without security_invoker that anon or authenticated can read.
  3. Test each one with curl and only the public key.
  4. Set security_invoker = true on every view in public, and add RLS policies where data disappears.
  5. Revoke access or move views out of public on Postgres versions older than 15.
  6. Check materialized views and security definer functions the same way.

The tables behind your views need checking too. How to tell if a Supabase table is public: https://leakyvibe.com/guides/how-to-check-if-supabase-table-is-public

The free LeakyVibe scan at the top of this page checks your live site from the outside for secret keys in public JavaScript and Supabase tables that answer the public key. It's a fast first check, not a full audit: it can't see your dashboard, your server, or data behind a login.

Official sources (checked 2026-11-03): Supabase, "Row Level Security" (https://supabase.com/docs/guides/database/postgres/row-level-security, section "Expose a view safely"), "Advisors" (lints 0010, 0016, 0028, 0029) (https://supabase.com/docs/guides/database/database-advisors); Supabase splinter lint 0010_security_definer_view (https://github.com/supabase/splinter); PostgreSQL, "CREATE VIEW" (https://www.postgresql.org/docs/current/sql-createview.html).

Check your app for this now

Free scan · about 15 seconds · no sign-up

Passive, read-only checks. Only scan apps you own or have permission to test.