What this thread does
The problem in plain words
Supabase tables in an exposed schema are reachable through the Data API when the request role has grants; Row Level Security then decides which rows it can access. Our recommendation: before launch, check grants and policy conditions rather than just checking whether RLS is on.
What the sources say
Supabase's official agent skill (supabase/agent-skills, MIT) includes a security checklist. Its points, in my words, with the policy and function details clarified against the docs:
- Enable RLS on every table in an exposed schema (
publicby default). Create policies that match the real access model. - Never use
user_metadataclaims for authorization; users can edit them. Useapp_metadata. - Deleting a user does not invalidate existing access tokens. The skill recommends signing out or revoking sessions first, short JWT expiry for sensitive apps, and checking
session_idagainstauth.sessionsfor strict guarantees. JWT claims can be stale until refresh. - Never expose the
service_roleor secret key in public clients; in Next.js,NEXT_PUBLIC_environment variables are sent to the browser. Use scoped personal access tokens for the CLI, Management API and MCP server. - Views bypass RLS by default; on Postgres 15 and above use
security_invoker = true. - When an UPDATE reads table columns, it also needs SELECT privileges and an applicable SELECT or ALL policy; the skill describes missing SELECT policies as returning 0 rows.
TO authenticatedalone is authentication without authorization; add an ownership test such as(select auth.uid()) = user_id. Our recommendation: for owner-only updates, check the caller's ownership of both existing and resulting rows; ifWITH CHECKis omitted from an UPDATE policy, PostgreSQL reusesUSINGfor the resulting row, as the PostgreSQL policy reference clarifies.SECURITY DEFINERfunctions run with their creator's privileges and can bypass RLS when that role does; by default any role can run a database function, as the function security docs explain. The skill recommends keeping privileged helpers in a non-exposed schema with anauth.uid()check and running database advisors after changes. Our recommendation: check the installed CLI's support before choosing an advisor command.- Storage upsert needs INSERT, SELECT and UPDATE policies; only INSERT is insufficient for overwrites (Storage access control).
Wording to give your agent
Our recommendation:
"Audit this Supabase project's security using the Supabase skill's checklist. List every table in exposed schemas with RLS status and each policy (command, role, USING, WITH CHECK). Flag policies that are true, ownership checks missing, user_metadata in policies, views without security_invoker, SECURITY DEFINER functions in public, public buckets, and any service key in client code. Do not change anything yet; show findings first."
Common mistakes
Our recommendation:
- Test as another user as well as the owner of the data; check more than whether RLS is "on".
- Do not fix a permission error by adding SECURITY DEFINER without reviewing access control.
- Do not assume a hidden page protects data; test the API.
Caveats
Our recommendation: treat this checklist as a starting point and check application-specific logic too; see the thread on proving tenant isolation with cross-tenant tests.
Sources
Primary source: Supabase docs, Row Level Security, alongside the maker's agent-skills checklist.
- Confirms: enable RLS on every table in an exposed schema;
user_metadatacan be changed by users throughsupabase.auth.update(), so authorization data belongs inapp_metadata; a secret key authorizes the service_role, which bypasses RLS when no user access token is supplied, and must never be used in the browser; views bypass RLS by default and on Postgres 15+ needsecurity_invoker = true(on older versions revoke access fromanonandauthenticatedor move the view to an unexposed schema);USINGdecides which existing rows an operation can touch whileWITH CHECKdecides whether the resulting row is allowed; a JWT can be stale until it refreshes; wrappingauth.uid()as(select auth.uid())lets Postgres cache it per statement when the result does not depend on row data, and policy filter columns should be indexed. - Adds: grants are checked before policies (a missing grant fails with error 42501), and adding policies does not remove existing grants, so revoke
anonandauthenticatedgrants where they should not exist. - Additional sources: the official skill supplies the token-deletion, role-only policy and scoped-token guidance; separate function-security and Storage pages document function privileges and upsert permissions. The PostgreSQL policy reference explains that an UPDATE reading table columns also needs SELECT privileges and an applicable SELECT or ALL policy. It also corrects the skill's claim that omitting WITH CHECK necessarily permits row reassignment.
Started from a post by @supabase, packaged by the editor. Original post