Supabase — Service Role Key
The Supabase service role key bypasses Row Level Security and grants full database access. It must never be exposed in client-side code.
Immediate Action Required
Deleting a leaked credential from a repository does not invalidate it. Assume it has already been copied. Follow the revocation steps below immediately, then investigate for unauthorized access.
What Is This Credential?
The Supabase service role key bypasses Row Level Security and grants full database access. It must never be exposed in client-side code.
Permissions Granted
- Full database read/write bypassing RLS
- Storage bucket management
- Auth user management
- Edge function invocation
Exposure & Blast Radius
- Full database read/write access bypassing all RLS policies
- Access to all user data including auth.users table
- Storage bucket manipulation
- Ability to create or delete users
Immediate Response Steps
Rotate the service role key
Go to Supabase Dashboard → Project Settings → API → Rotate the service_role key.
Check database logs
Review Supabase Dashboard → Logs → Database for unexpected queries.
Audit auth.users table
Check for unauthorized user creation or modification.
Update all server-side consumers
Update environment variables in all backend services and edge functions.
Revocation vs Rotation
Revocation
Rotate the key in Supabase Dashboard → Project Settings → API. The old key is immediately invalidated.
Rotation
Use the 'Rotate' function in Project Settings → API. This atomically replaces the key.
Grace Period & Session Persistence
Grace Period
None. Key rotation immediately invalidates the previous key.
Session Persistence
JWT tokens issued using the service role key remain valid until their expiry. Review active sessions in the Auth dashboard.
Investigation Checklist
- Review database logs for unexpected queries
- Check auth.users for unauthorized accounts
- Review storage access logs
- Look for unexpected RLS policy changes
- Check edge function invocation logs
Recovery Steps
- Update all server-side environment variables
- Review and revoke suspicious user sessions
- Audit RLS policies to ensure they are correctly configured
- Never use the service role key in client-side code
Prevention
- Never expose the service role key in frontend code
- Use the anon key with proper RLS policies for client-side access
- Store the service role key only in server-side environment variables
- Enable Supabase's built-in secret scanning warnings
Sources & Evidence
Always verify critical instructions with official provider documentation before taking action. Provider behavior may change without notice.
Found an issue with this playbook?
If these instructions are incorrect, outdated, or missing important information, please report it so we can improve the playbook.
Report an Issue on GitHub