feat(security): enable RLS and migrate to getClaims()#129
Conversation
WS-RLS: Auth Standardization - Enable RLS on all data tables (deny-all policy) - Replace jwt.verify() with supabase.auth.getClaims() - Update to new key format (supabasePublishableKey, supabaseSecretKey) - Remove jwtSecret dependency (not needed with getClaims) - Add dual client pattern (supabase + getSupabaseAdmin) - Add Security section to README - Update .env.example with new key format RLS blocks direct data queries via publishable key while: - API data access via Drizzle (DATABASE_URL) bypasses RLS - Auth endpoints (/auth/v1/*) unaffected by RLS getClaims() benefits: - Auto-detects key type (asymmetric/symmetric) - Local verification with asymmetric keys (faster) - No JWT_SECRET needed in env
Summary of ChangesHello @JDIZM, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the application's security posture by standardizing authentication and implementing robust defense-in-depth mechanisms. It migrates JWT verification to Supabase's Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces significant security enhancements by enabling Row Level Security (RLS) and migrating from JWT verification to Supabase's getClaims() method. The changes are well-structured, particularly the introduction of separate Supabase clients for regular and admin operations, which is a great practice. The documentation updates in the README are clear and comprehensive. My review includes a few suggestions to improve configuration robustness, project hygiene in .gitignore, and adherence to migration naming conventions.
- Remove jsonwebtoken and @types/jsonwebtoken (no longer needed) - Update token-test.ts to use getClaims() instead of jwt.verify() - Expand README to explain how getClaims() works - No JWT_SECRET environment variable needed anymore
- Remove personal settings from .gitignore (use global gitignore) - Throw error if SUPABASE_PUBLISHABLE_KEY not set (fail fast) - Remove legacy key references from .env.example - Simplify config comment (remove '2025+ format' wording)
WS-RLS: Auth Standardization
Changes
supabase.auth.getClaims()supabasePublishableKeyandsupabaseSecretKey(with legacy fallback)supabasefor auth,getSupabaseAdmin()for admin opsSecurity Model
Why getClaims() instead of jwt.verify()?
jwt.verify(token, JWT_SECRET)supabase.auth.getClaims(token)SUPABASE_AUTH_JWT_SECRETenv varjsonwebtokenHow getClaims() works:
sb_publishable_*): Fetches JWKS, verifies locally with Web Crypto APIeyJhbG...): Falls back togetUser()server callEither way, no JWT_SECRET needed - verification is handled automatically.
Supabase Key Migration (2025+)
SUPABASE_ANON_KEYSUPABASE_PUBLISHABLE_KEYSUPABASE_SERVICE_ROLE_KEYSUPABASE_SECRET_KEYSUPABASE_AUTH_JWT_SECRETTesting