Category: Supabase and databases

Supabase: SQL view shows other people's data despite RLS enabled

Read this guide in Polish

The query directly to the table respects RLS policies, but the SQL view API returns other people's lines to the user. PostgreSQL views standard check the permissions of the view owner; a view created by the privileged role can bypass the RLS policies of the base tables.

How to determine the source of the error

Check whether the endpoint reads the table or VIEW and what role the view was created. Test the same filter directly on the table.

Verify the Postgres version and the security invoker option of the view, then compare results for two independent user tokens.

What to do step by step

1. In PostgreSQL 15 or later, set security invoker=true to check the permissions of the calling role and the RLS rule.

2 . In the older PostgreSQL or with a private view limit GRANT for an anon/authenticated and keep the view in a scheme not listed by Data API.

How to check the score

After the change, each user sees only allowed lines, and an anonymous query to private data does not give access to the view.

What to do

Do not assume that the inclusion of RLS only on the table protects all created views or functions of SECURITY DEFINITION.