fix: restrict team RLS policy to members only#117
fix: restrict team RLS policy to members only#117FOX-KNIGHT wants to merge 3 commits intoAOSSIE-Org:mainfrom
Conversation
📝 WalkthroughWalkthroughRemoved the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
sqls/02_user_auth_policies.sql (1)
25-27: Consider using the user_teams view for consistency.The policy queries the
userstable directly, while the existing "Users can view team members" policy (lines 46-48) uses theuser_teamsview defined at line 14. Using the view consistently across all policies would improve maintainability.🔎 Proposed refactor using user_teams view
CREATE POLICY "Team members can view their team" ON teams FOR SELECT USING ( id IN ( - SELECT team_id FROM users WHERE id = auth.uid() + SELECT team_id FROM user_teams WHERE id = auth.uid() ) );
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
pubspec.yamlsqls/02_user_auth_policies.sql
🔇 Additional comments (2)
sqls/02_user_auth_policies.sql (2)
34-36: Verify permissive INSERT policies and GRANT ALL permissions are intentional.While the SELECT policy was tightened to restrict team visibility, the INSERT policies (lines 36, 57) allow any authenticated user to create teams and users with
WITH CHECK (TRUE). Additionally,GRANT ALL(lines 62-63) provides full permissions to both anonymous and authenticated users.Please confirm this permission model is intentional and aligns with your security requirements, especially given the effort to restrict SELECT access.
Consider whether:
- Team creation should be restricted to specific roles or conditions
- User creation should validate team membership or require authorization
- More granular grants (SELECT, INSERT, UPDATE, DELETE) would be more appropriate than GRANT ALL
Also applies to: 55-57, 62-63
25-27: Security fix correctly implements membership check.The policy at lines 25-27 successfully restricts team visibility to only teams where the authenticated user is a member. The subquery pattern
id IN (SELECT team_id FROM users WHERE id = auth.uid())correctly prevents the vulnerability described in issue #116.The required indexes already exist in the schema:
idx_users_team_idon users(team_id) and the primary key index on users(id).
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
pubspec.yaml (1)
95-95: Good cleanup - addresses previous feedback.The removal of the
ELL-ena-logo/asset entry correctly addresses the prior review concern about bundling unrelated changes with the security fix. The launcher icon configuration (lines 130, 132) can still reference these files since they're processed at build time, not runtime.The blank line could optionally be removed for cleaner formatting.
🔎 Optional: Remove blank line
assets: - .env -
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
pubspec.yaml
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: SharkyBytes
Repo: AOSSIE-Org/Ell-ena PR: 3
File: lib/screens/auth/signup_screen.dart:98-106
Timestamp: 2025-07-03T00:01:13.873Z
Learning: In the Ell-ena Flutter project, the team is keeping authentication validation simple during development (e.g., 6-character minimum passwords) for testing convenience, with plans to enforce stronger security rules later when integrating full authentication flows.
Closes #116
📝 Description
This PR addresses a Critical Security Vulnerability in
sqls/02_user_auth_policies.sql.The previous Row-Level Security (RLS) policy for the
teamstable was configured with a wildcardTRUEcondition, which allowed any authenticated user to query and view all teams in the database, including privateteam_codes and admin emails.This fix restricts access so that users can only view teams they are explicitly members of.
🔧 Changes Made
sqls/02_user_auth_policies.sql:USING (TRUE)policy.USING (id IN (SELECT team_id FROM users WHERE id = auth.uid())).✅ Verified App Execution
Validating the build integrity after security patches.
✅ Checklist
Summary by CodeRabbit
Security
Chores
✏️ Tip: You can customize this high-level summary in your review settings.