Fix Hardcoded Supabase Service Key Bypass - #2037
Conversation
|
@ArshVermaGit is attempting to deploy a commit to the ritesh Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughBackend Supabase client initialization switches from service-role key to anon key to enforce Row-Level Security. The environment template example and startup configuration are updated to reflect the change from ChangesSupabase Client Authentication via Anon Key
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
ArshVermaGit
left a comment
There was a problem hiding this comment.
Hi @ritesh-1918 ! The issue has been resolved. Please review the PR and merge it under GSSoC. Thanks!
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend/main.py`:
- Around line 38-44: Multiple backend modules are instantiating privileged
Supabase service-role clients (create_client(url, key) with SUPABASE_SERVICE_KEY
/ SUPABASE_SERVICE_ROLE_KEY) which can bypass RLS; centralize and lock down
service-role usage by introducing a single admin-only factory (e.g., an explicit
get_admin_supabase_client function) located in a secure module and replace
direct create_client calls in rag_service.py, notification_routing.py,
auto_close_service.py and seed_company_settings.py with either the safe anon
client or the guarded admin factory; enforce an allowlist/justification check in
that factory (throw/deny if called from tenant/request-facing paths) and
document/limit its use to admin-only scripts or endpoints only.
- Around line 42-47: The current code creates a single global Supabase client
with create_client(url, key) and never attaches the request JWT from
extract_token(), causing RLS checks to run as anon; change to create or
configure a request-scoped Supabase client (or set the session/auth on the
client) inside each incoming request handler before any RLS-protected calls
(e.g., before get_system_settings, get_ticket_by_id, ticket/ticket_messages
reads/writes and profile lookups), by using the bearer/cookie token returned
from extract_token() so get_current_user() and subsequent supabase.table(...)
queries execute with the correct user context rather than the global anon
client.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3d427bd4-cbed-42dd-8ab4-6b0480995099
📒 Files selected for processing (2)
backend/.env.examplebackend/main.py
|
Hi @ArshVermaGit! Thanks for the contribution. I have triaged your PR and set it to merge into the
Welcome to the HELPDESK.AI developer family! 🚀💻 |
fb4320c
into
riteshbonthalakoti:gssoc
Description
This PR addresses a critical security vulnerability where the FastAPI backend was connecting to the Supabase database using the Service Role Key instead of the Anon Key.
Changes Made:
backend/main.pyto initialize the Supabase client usingSUPABASE_ANON_KEY.backend/.env.exampleto requireSUPABASE_ANON_KEYinstead ofSUPABASE_SERVICE_KEY.By swapping to the Anon Key, the global Supabase client no longer bypasses Row-Level Security (RLS). Any data operations performed will be subjected to the RLS policies defined in the database, preventing unauthorized mass data modification or deletion.
Resolved Issue
Resolves #2036
Summary by CodeRabbit