V.I.B.Eby TNAADO

Postgres table access check

See which Neon or other Postgres tables are shared too widely.

Check my database
  • Customer table is open
  • V.I.B.E reads your database rules
  • Table rule is fixed

Query

Read-only. It lists table rules, permissions and logins, and changes nothing.

View the query
-- V.I.B.E Postgres check. Read-only: it lists table rules, permissions and logins
-- from the system catalogs. It does not read, change or delete any rows.
with web as (
  -- Roles a web data API signs visitors in as.
  select r.oid, r.rolname, case when r.rolname = 'authenticated' then 'signedIn' else 'anon' end as audience
  from pg_catalog.pg_roles r where r.rolname in ('anon', 'anonymous', 'authenticated')
),
spaces as (
  select n.oid, n.nspname from pg_catalog.pg_namespace n
  where n.nspname::text !~ '^(pg_|_)' and n.nspname not in ('information_schema', 'auth', 'neon_auth', 'neon', 'pgrst',
    'storage', 'extensions', 'graphql', 'graphql_public', 'realtime', 'vault', 'pgsodium', 'pgsodium_masks',
    'supabase_functions', 'supabase_migrations', 'supavisor', 'net', 'cron', 'pgbouncer', 'pgmq')
),
rel as (
  select c.oid, c.relnamespace as space, c.relkind, c.relrowsecurity, c.relforcerowsecurity, c.reloptions, s.nspname,
    o.rolcanlogin as owner_login,
    case when s.nspname = 'public' then c.relname::text else s.nspname::text || '.' || c.relname::text end as label
  from pg_catalog.pg_class c join spaces s on s.oid = c.relnamespace
  join pg_catalog.pg_roles o on o.oid = c.relowner
  where c.relkind in ('r', 'p', 'v', 'm', 'f')
    and not exists (select 1 from pg_catalog.pg_depend d
      where d.classid = 'pg_catalog.pg_class'::pg_catalog.regclass::pg_catalog.oid and d.objid = c.oid and d.deptype = 'e')
),
-- What each web role, and PUBLIC (every login), may do with each table.
may as (
  select rel.oid, who.audience, a.action, a.main
  from rel
  cross join (select rolname::text as name, audience from web union all select 'public', 'everyLogin') who
  cross join lateral (values
    ('read', true, pg_catalog.has_any_column_privilege(who.name, rel.oid, 'select')),
    ('add', true, pg_catalog.has_any_column_privilege(who.name, rel.oid, 'insert') and rel.relkind <> 'm'
      and (rel.relkind <> 'v' or pg_catalog.pg_relation_is_updatable(rel.oid, true) & 8 <> 0)),
    ('change', true, pg_catalog.has_any_column_privilege(who.name, rel.oid, 'update') and rel.relkind <> 'm'
      and (rel.relkind <> 'v' or pg_catalog.pg_relation_is_updatable(rel.oid, true) & 4 <> 0)),
    ('delete', true, pg_catalog.has_table_privilege(who.name, rel.oid, 'delete') and rel.relkind <> 'm'
      and (rel.relkind <> 'v' or pg_catalog.pg_relation_is_updatable(rel.oid, true) & 16 <> 0)),
    ('truncate', false, rel.relkind in ('r', 'p', 'f') and pg_catalog.has_table_privilege(who.name, rel.oid, 'truncate')),
    ('trigger', false, rel.relkind in ('r', 'p', 'f') and pg_catalog.has_table_privilege(who.name, rel.oid, 'trigger'))
  ) as a(action, main, allowed)
  where a.allowed and pg_catalog.has_schema_privilege(who.name, rel.space, 'usage')
),
-- One row for each table, so a database with thousands of tables is still quick.
acts as (
  select m.oid,
    pg_catalog.json_agg(m.action) filter (where m.audience = 'everyLogin' and m.main) as every_login,
    pg_catalog.json_agg(distinct m.action) filter (where m.audience = 'anon' and m.main) as anon,
    pg_catalog.json_agg(distinct m.action) filter (where m.audience = 'signedIn' and m.main) as signed_in,
    pg_catalog.json_agg(distinct m.action) filter (where m.audience = 'anon' and not m.main) as anon_extra,
    pg_catalog.json_agg(distinct m.action) filter (where m.audience = 'signedIn' and not m.main) as signed_in_extra
  from may m group by m.oid
),
definer as (
  select f.oid, f.proname, f.prokind,
    case when s.nspname = 'public' then f.proname::text else s.nspname::text || '.' || f.proname::text end as label,
    s.nspname, pg_catalog.pg_get_function_identity_arguments(f.oid) as args,
    f.prorettype in ('pg_catalog.trigger'::pg_catalog.regtype::pg_catalog.oid,
      'pg_catalog.event_trigger'::pg_catalog.regtype::pg_catalog.oid) as is_trigger,
    exists (select 1 from pg_catalog.unnest(f.proconfig) as setting(item)
      where pg_catalog.starts_with(setting.item, 'search_path=')) as fixed_path,
    exists (select 1 from web w where w.audience = 'anon' and pg_catalog.has_schema_privilege(w.oid, s.oid, 'usage')
      and pg_catalog.has_function_privilege(w.oid, f.oid, 'execute')) as anon,
    exists (select 1 from web w where w.audience = 'signedIn' and pg_catalog.has_schema_privilege(w.oid, s.oid, 'usage')
      and pg_catalog.has_function_privilege(w.oid, f.oid, 'execute')) as signed_in
  from pg_catalog.pg_proc f join spaces s on s.oid = f.pronamespace
  where f.prosecdef
    and not exists (select 1 from pg_catalog.pg_depend d
      where d.classid = 'pg_catalog.pg_proc'::pg_catalog.regclass::pg_catalog.oid and d.objid = f.oid and d.deptype = 'e')
)
select pg_catalog.json_build_object(
  'vibe', 1,
  'database', 'postgres',
  'webRoles', (select coalesce(pg_catalog.json_agg(web.rolname order by web.rolname), '[]') from web),
  'schemas', (select coalesce(pg_catalog.json_agg(pg_catalog.json_build_object('name', s.nspname, 'exposed', false)
    order by s.nspname), '[]') from spaces s where s.nspname <> 'public'),
  'tables', (select coalesce(pg_catalog.json_agg(pg_catalog.json_build_object(
      'name', rel.label, 'schema', rel.nspname,
      'kind', case rel.relkind when 'v' then 'view' when 'm' then 'materialized' when 'f' then 'foreign' else 'table' end,
      'rls', rel.relrowsecurity,
      'forced', rel.relforcerowsecurity,
      'ownerLogin', rel.owner_login,
      'invoker', coalesce(pg_catalog.array_to_string(rel.reloptions, ',') ~* 'security_invoker=(t|y|on|1)', false),
      'anon', coalesce(acts.anon, '[]'),
      'signedIn', coalesce(acts.signed_in, '[]'),
      'anonExtra', coalesce(acts.anon_extra, '[]'),
      'signedInExtra', coalesce(acts.signed_in_extra, '[]'),
      'everyLogin', coalesce(acts.every_login, '[]')
    ) order by rel.label), '[]') from rel left join acts on acts.oid = rel.oid),
  'policies', (select coalesce(pg_catalog.json_agg(pg_catalog.json_build_object(
      'table', rel.label, 'schema', rel.nspname, 'name', p.policyname, 'permissive', p.permissive = 'PERMISSIVE',
      'command', p.cmd, 'roles', p.roles, 'using', p.qual, 'check', p.with_check
    ) order by rel.label, p.policyname), '[]')
    from pg_catalog.pg_policies p join rel on rel.nspname = p.schemaname
      and rel.label = case when p.schemaname = 'public' then p.tablename::text else p.schemaname::text || '.' || p.tablename::text end),
  'functions', (select coalesce(pg_catalog.json_agg(pg_catalog.json_build_object(
      'name', d.label, 'schema', d.nspname, 'args', d.args,
      'kind', case d.prokind when 'p' then 'procedure' else 'function' end,
      'anon', d.anon, 'signedIn', d.signed_in
    ) order by d.label, d.args), '[]') from definer d where not d.is_trigger),
  'loosePaths', (select coalesce(pg_catalog.json_agg(pg_catalog.json_build_object(
      'name', d.label, 'schema', d.nspname, 'args', d.args,
      'kind', case d.prokind when 'p' then 'procedure' else 'function' end,
      'web', not d.is_trigger and (d.anon or d.signed_in)
    ) order by d.label, d.args), '[]') from definer d where not d.fixed_path),
  -- Logins that can skip row rules, either directly or by switching to a role that can.
  'admins', (select coalesce(pg_catalog.json_agg(r.rolname order by r.rolname), '[]') from pg_catalog.pg_roles r
    where r.rolcanlogin and r.rolname::text !~ '^pg_'
      and r.rolname not in ('cloud_admin', 'neon_service', 'supabase_admin', 'rdsadmin', 'azuresu', 'cloudsqladmin')
      and exists (select 1 from pg_catalog.pg_roles p where (p.rolsuper or p.rolbypassrls)
        and pg_catalog.pg_has_role(r.oid, p.oid, 'member')))
) as vibe_report;

Examples

Checks
  • Data API tables with row security switched off
  • Data API rules open to anyone or to any signed-in account
  • Public actions and views that skip row rules
  • Saved actions with a loose search path
  • Tables shared with every database login, where there is no data API
  • Logins and owners that skip row rules

A data API with an open table

This made-up bookings table sits behind a data API, a web address that lets an app ask the database directly. Its lock is off, and signed-in accounts may read and change it, so anyone who makes an account reaches every row. In the corrected version the lock is on and a rule shows each person only their own bookings.

  • Any signed-in user can read and change every row in “bookings”RLS disabled; authenticated may read, change

    In one run, turn the lock on and add a rule for each thing your app does: read, add, change or delete. Anything without a rule stops working, saving included.

Checked again after the fix: none of these results come back.

A table every login can read

A made-up invoices table was shared with PUBLIC. The PostgreSQL manual says that word means all roles, including those created later, so a reporting login or a contractor’s account added next month could read it from the first day. The corrected version takes that share away.

  • Every database login can read “invoices”invoices: PUBLIC may read

    Remove the shared access. Give it only to the login your app uses.

Checked again after the fix: none of these results come back.

What happens when row security has no rule?

Row level security decides which rows a login may see or change. The manual says that when it is switched on and no policy exists, no rows are visible and none can be modified. Superusers and roles with the BYPASSRLS attribute always skip it. A table’s owner normally skips it too, unless the table is set to force it. An app that connects as the owner can therefore pass every test while its rules do nothing, which is why the result also looks at logins and owners.

Why do saved functions matter?

A function marked SECURITY DEFINER runs with the rights of the user who owns it. The manual notes that new functions can be run by PUBLIC by default, and suggests revoking that and granting only to those who need it. It also asks for a fixed search_path, the list of places a function looks for names, so that nobody can slip in a look-alike table. The result names public actions that skip row rules and saved actions with a loose path.

Can a view show more than the table allows?

By default a view applies the row rules of whoever owns the view, not those of the person asking. PostgreSQL offers a security_invoker setting that applies the asker’s rights instead. A view built over a locked table can therefore show what the table itself would refuse.

Using the Neon Data API?

Neon describes its Data API as an HTTP query service for apps and agents, and says every request is authorized by your PostgreSQL grants and row level security policies. It warns that a missing or wrong policy can expose a table to anyone who has the endpoint address. Treat each table the API reaches as a public door until a rule says otherwise.

How do you run the query?

Copy the query, open your database’s SQL editor, choose the branch and database your live app uses, run it, then copy the single result cell. It reads the system catalogs, which are the tables PostgreSQL keeps about itself, and your rows are not part of the result.

Change access one table at a time

Export your data first. Apply one suggested statement, run the query again, then sign in as two different people and open the screens that use that table. Never grant wider access just to make an error go away.

Sources, read 30 November 2026

V.I.B.E is made by TNAADO. It is not part of, or endorsed by, Neon or the PostgreSQL project.

Advanced app builds

TNAADO builds multiplatform products that take payments and protect sensitive data.

Start a project