Review findings:
Finding 1 (E:/ai-stats-public-workspaces/supabase/migrations/20260121000003_add_rls_policies.sql:246-250) [added]
[P0] Join-request insert policy allows arbitrary team/invite linkage
team_join_requests_insert only checks requester_user_id = auth.uid(). Any authenticated user can insert requests for arbitrary team_id, set invite_id, and prefill decision fields/status. This enables request spoofing and is the first half of a privilege-escalation chain.
Finding 2 (E:/ai-stats-public-workspaces/apps/web/src/app/(dashboard)/settings/teams/actions.ts:527-544) [added]
[P0] Approval path trusts invite role without team match validation
approveJoinRequest loads invite.role by invite_id and applies it to membership, but never verifies invite.team_id === request.team_id. Combined with the permissive insert policy, an attacker can submit a request for Team A using an invite from Team B (e.g., role owner), and if approved, gets elevated role in Team A.
Finding 3 (E:/ai-stats-public-workspaces/apps/web/src/app/(dashboard)/settings/teams/actions.ts:509-546) [added]
[P1] Approval flow is non-atomic and can leave inconsistent state
Request status is updated to approved before membership upsert and invite usage increment. If later steps fail, the request is no longer pending but member insertion may not occur, creating a stuck, inconsistent state that is hard to recover from via normal flow.
Finding 4 (E:/ai-stats-public-workspaces/apps/web/src/app/(dashboard)/settings/teams/actions.ts:579-583) [added]
[P1] Reject flow can rewrite already-decided requests
rejectJoinRequest updates by id only and does not require current status pending. This can flip previously approved requests to denied in audit state while membership may already exist, causing integrity drift.
Finding 5 (E:/ai-stats-public-workspaces/apps/web/src/app/(dashboard)/settings/teams/actions.ts:385-424) [added]
[P2] Admin invite management is inconsistent with policy intent
RLS allows team admins to mutate invites, but server actions/UI restrict revoke/reveal mostly to creator/owner. This is a functional mismatch likely to confuse operations and incident response for admins.
My request for Codex:
I think owner should basically just be for the creator - but they are shown as owner, but have the same privalages as admins - except AHH ONLY OWNERS can delete the team, other than that, everything else is the same as an admin?