Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
6 Skipped Deployments
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
afc05ae to
910db19
Compare
910db19 to
078eebe
Compare
fe00e8c to
563def8
Compare
…odes A claim-by-claim check against the supabase-postgres-best-practices skill references, the Supacademy RLS course, and Postgres itself. The worst finding: the team membership policy never ran. `team_id in (select auth.jwt() -> 'app_metadata' -> 'teams')` fails at create policy with `operator does not exist: uuid = jsonb`, because -> yields one jsonb value. Replaced with jsonb containment and verified: a member of a team sees exactly their row, a member of none sees zero. Also corrected: permissive policies OR together while a restrictive one ANDs and only narrows what a permissive policy granted; force row level security and who it does not apply to; revoking execute on helper functions without breaking the policy that calls them; null = user_id is unknown, not false; an update that reads the row needs a select policy; auth.jwt() returns jsonb; views run with owner rights because security_invoker defaults to false; a composite primary key leads with its first column; and updateUser() is the method, not update(). Two failure modes the guide never mentioned: - Materialized views, in Expose a view safely. One stores its own rows, so it consults no policy, and Postgres rejects both security_invoker and enable row level security on it. - Debug a policy: which role ran the query, pg_policies, and separating a hidden row from an absent one. Co-Authored-By: Claude Opus 5 <[email protected]>
563def8 to
894715b
Compare
|
I'm going to close this for now. Unsure if I want this as there is a lot of AI specificity that is maybe not necessary. |
Stacked on #49276. Review that first.
Problem
A claim-by-claim check of the restructured guide against the RLS basics and RLS performance skill references, the Supacademy RLS course, and Postgres itself.
The worst finding: the team membership policy never ran.
team_id in (select auth.jwt() -> 'app_metadata' -> 'teams')fails atcreate policywithoperator does not exist: uuid = jsonb, because->returns one jsonb value andin (select …)comparesteam_idagainst it.Three failure modes were missing entirely — recursive policies, materialized views, and how to debug a policy that denies too much. All three are treated as core by both reference sources.
Solution
Corrections
as restrictiveappeared once, in the MFA example, unexplained.force row level security— table owners skip RLS unless forced, and forcing still doesn't apply to superusers orbypassrlsroles. On Supabasepostgresisn't a superuser but does havebypassrls.revoke executeon helpers — revoke frompublic, then grantusageandexecuteto the role the policy uses. Policy expressions run as the caller, so revoking from that role breaks the policy that calls the function.null = user_idis unknown, not false.auth.jwt()returns claims as jsonb, not the token string.security_invokerdefaults to false, not because Postgres marks themsecurity definer.supabase.auth.update()is not a method. It'supdateUser().New sections
Avoid recursive policies— two tables whose policies read each other raise42P17. A sharing feature produces exactly that shape. Broken with a security definer helper that reads membership as its owner, so the second policy never runs.Expose a view safely— a materialized view stores its own rows, consults no policy, and Postgres rejects bothsecurity_invokerandenable row level securityon one.Debug a policy— which role ran the query,pg_policies, comparing a privileged read against the client's, and grants before rewriting anything.Also
search_pathstated as a principle — pin it to a schema callers can't write to — rather than the literal'', which contradicted the event trigger recipe inevent-triggers.mdx. Custom claims and RBAC, Storage access control, and Realtime authorization added toRelated content.Verification
Every claim was executed against a local Postgres 17 before being written down.
ERROR: operator does not exist: uuid = jsonb, atcreate policyERROR: 42P17: infinite recursion detected in policy for relation "lists"security_invokeron a matviewERROR: unrecognized parameter "security_invoker"ERROR: ALTER action ENABLE ROW SECURITY cannot be performedcreate policyon a matviewERROR: "mv2" is not a tablesearch_path = ''resolvespg_catalogformat()andcurrent_setting()resolve unqualifiedThe SQL in
Avoid recursive policieswas re-extracted from the rendered MDX and run again, so the published blocks are the ones that were tested.Manual testing
Avoid recursive policiesandDebug a policyappear in the table of contents underRLS reference.Avoid recursive policies. It jumps to that section.Expose a view safely. The materialized view guidance follows the Postgres 15 note.auth.jwt()team policy. It uses jsonb containment and carriesfor selectandto authenticated.