Supabase¶
Scope: web apps, mobile apps and games whose clients call Supabase directly, on the hosted Supabase platform (projects on Postgres 15 and 17), with the Supabase CLI 3 and supabase-js 2 (CLI 2 still gets security fixes, but no new features, after the move to CLI 3): Row Level Security and grants, API keys, Storage, Edge Functions, migrations and environments, database connections, backups and Auth settings. Because clients query the database through the Data API, Row Level Security carries the server-side authorisation that SEC-1 asks for, and the key in the client is public (SEC-11 in Security). A Supabase database is PostgreSQL, so PostgreSQL applies to its schema, indexes and migrations; its rules aren't repeated here. Sign-in in general is covered in Authentication and sessions, personal data in Privacy and personal data, browser apps in Web front end, mobile games in Mobile games, and connecting from serverless functions in Serverless and edge hosting. For a document-database backend of the same kind, see Firebase.
Entries are sorted by score from 1 to 10 (criteria): 9โ10 start here or strongly recommended, 6โ8 recommended, 1โ5 further reading or conditional.
Adopted references¶
- 8 Production Checklist: performance, availability (including your own SMTP server for Auth emails), deployment, and Auth rate limits and abuse prevention. Its security part is now the Production security checklist.
- 8 Production security checklist: Row Level Security, SSL enforcement and network restrictions, account and organization access, Auth settings, and a threat review.
- 8 Row Level Security: the baseline for data access: how grants and policies combine, securing a table step by step, testing policies with pgTAP, indexes for policies, helper functions such as
auth.uid()andauth.jwt(), andsecurity definerfunctions. - 8 Securing your API: grants and RLS for the Data API, default privileges, dedicated API schemas and pre-request checks.
- 7 API keys: which key to use where, publishable and secret keys and the legacy
anonandservice_rolekeys, and handling secret keys safely. - 7 Shared Responsibility Model: what Supabase manages and what stays your job, such as access management, your data, security controls, schema design and third-party services.
- 7 Managing Environments: local development with the CLI, migrations, and releasing them to staging and production projects with GitHub Actions. Read with Deploy database migrations.
- 7 Advisors: the Security, Performance and Health Advisors, their checks, and how to run them from the dashboard, the CLI and the Management API.
- 7 Database Backups: daily backups for each plan, physical and logical backups, restoring, and point-in-time recovery.
- 7 Connect to your database: which connection method to use from where, the poolers' session and transaction modes, and client settings for serverless functions.
- 7 Securing Edge Functions: the auth modes for calls from users, from other services, from anyone, and from external webhooks.
- 6 Secure configuration of Supabase products: an index of the hardening guides for Auth, the database, Storage and Realtime.
Key rules¶
Row Level Security and grants¶
- 10
SUPABASE-1Enable Row Level Security on every table in an exposed schema, such aspublic, and grant theanonandauthenticatedroles only the operations your app needs. A table without RLS is readable and writable by any role with a grant on it, and policies don't remove grants. On existing projects, new tables inpublicget every privilege by default, so turn off "Automatically expose new tables" or revoke the default privileges. This appliesSEC-1andPG-15. (Row Level Security, Grants and policies, Securing your API: default privileges, Production security checklist: database) - 9
SUPABASE-2Never createsecurity definerfunctions in an exposed schema, setsearch_path = ''on every one, and create views withsecurity_invoker = trueor keep them out of exposed schemas. Both run with their owner's privileges and bypass RLS. Asecurity definerfunction in an exposed schema can be called through the Data API, and new functions are executable by every role by default. (Row Level Security: use security definer functions, Views and RLS, Expose a view safely, Securing your API: default privileges) - 8
SUPABASE-3Write a separate policy for each operation, name its role withto authenticatedorto anon, compare owner columns with(select auth.uid()), addwith checkto insert and update policies, and base authorisation onapp_metadata, never onuser_metadata, which users can change themselves. (Row Level Security: write a policy for each operation, Specify roles in your policies, auth.jwt()) - 7
SUPABASE-4Test the policies of every table with pgTAP: a test file per table undersupabase/teststhat asserts which operations each role may and may not perform, run withsupabase test dbon every pull request. Until the tests pass, you don't know whether the policies do what you intended; test the denied cases as well as the allowed ones. (Row Level Security: secure a table with RLS, Policy tests, Testing overview: best practices) - 7
SUPABASE-5Index every column that policies filter on, and wrapauth.uid()andauth.jwt()in aselectso that Postgres evaluates them once per statement instead of once per row. This appliesPG-5to policies. (Row Level Security: add indexes, Call functions with select) - 7
SUPABASE-6If you enable anonymous sign-ins, check theis_anonymousclaim in restrictive policies on data that only permanent users may reach, and protect the sign-in endpoint with CAPTCHA. Anonymous users get the sameauthenticatedrole as permanent users, and bots can create them in bulk to fill your database. (Anonymous Sign-Ins: access control, Abuse prevention and rate limits) - 7
SUPABASE-7Keep Storage buckets private unless every file in them may be public, control access with policies onstorage.objects, for example per user folder, and give temporary access to private files with signed URLs. Anyone who has the URL of a file in a public bucket can download it. (Storage Buckets: access model, Storage Access Control)
Keys and Edge Functions¶
- 9
SUPABASE-8Put only the publishable key, or the legacyanonkey, in clients, and keep secret keys and theservice_rolekey in servers and Edge Functions, out of source control. Secret keys bypass RLS, so a leaked one exposes all of the project's data. Give each backend component its own secret key, so that one leak forces only one rotation, and move off the legacy JWT-based keys, which Supabase is deprecating by the end of 2026. This appliesSEC-11andSEC-2. (API keys: which key do you use?, Handling secret keys safely, Migrating to publishable and secret API keys) - 7
SUPABASE-9Check every caller of an Edge Function: keepverify_jwton for functions that users call, and query with the client that applies their RLS policies; use the admin client, which bypasses RLS, only for work that must cross policies, and verify the signature of external webhooks. Keep third-party credentials in Edge Function secrets, and the localsupabase/functions/.envfile out of Git. (Securing Edge Functions: authenticated user calls, External webhooks, Edge Functions, Environment variables)
Migrations and environments¶
- 8
SUPABASE-10Make every schema change, including RLS policies, grants and functions, a migration file insupabase/migrationsunder version control, and never change the production database directly in the dashboard. Test migrations on the local stack and on a staging project or preview branch, and deploy them from CI or the GitHub integration rather than from a developer's machine. This appliesDATA-2andSEC-16. (Deploy database migrations: working with a team, Row Level Security: enable RLS and set the grants, Managing Environments: deploy a migration, Branching, Production Checklist: deployment)
Connections and operations¶
- 8
SUPABASE-11Plan backups for your recovery point objective: Supabase backs up only paid-plan projects daily, so on the Free plan export the database regularly withsupabase db dump --remote(CLI 3 dumps the local stack without--remote) and keep the copies off-site, and on paid plans enable point-in-time recovery when losing up to a day of data is too much. Database backups don't include the files in Storage, and deleting a project also deletes its backups. This is how Supabase projects followDATA-8. (Database Backups, Point-in-Time recovery, Production Checklist: availability, Migrating to Supabase CLI v3) - 7
SUPABASE-12Connect each runtime the way Supabase recommends: clients through the Data API, serverless and edge functions through the shared pooler in transaction mode, with prepared statements off and a pool of one connection per instance, and migrations,pg_dumpand long-running backends through a direct connection or the pooler's session mode. This is how Supabase projects followPG-9andHOST-5. (Connect to your database: which connection method do you use?, Configure your client) - 7
SUPABASE-13Turn on SSL enforcement and network restrictions for the database. Postgres and its poolers accept connections without SSL until you enforce it, and network restrictions limit which IP ranges can connect at all; the HTTP APIs always use TLS. This is how Supabase projects followSEC-13,PG-14andSEC-20. (Production security checklist: database, Postgres SSL Enforcement, Network Restrictions) - 6
SUPABASE-14Leave the Spend Cap on, or watch the organization's usage page when it's off, so that an attack or a bug can't run up unlimited charges. With the cap on, usage beyond the plan's quota is blocked for items such as egress, Edge Function invocations, monthly active users and storage; compute, point-in-time recovery and other add-ons you opted into aren't covered. This is how Supabase projects followOPS-17. (Control your costs: Spend Cap)
Auth settings¶
- 7
SUPABASE-15Configure Supabase Auth for production: turn on email confirmations, send auth email through your own SMTP server, enable CAPTCHA on sign-up, sign-in and password reset, let one-time passwords expire within an hour, and review the rate limits. The built-in email service sends only two emails an hour. Rate limits and CAPTCHA are how a Supabase project limits sign-in attempts (AUTH-14). (Production security checklist: Auth, Production Checklist: availability, Enable CAPTCHA Protection, Rate limits)
How to enforce¶
Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.
- 7 Supabase Advisors: deterministic checks, based on the splinter lints, that run in the dashboard, or in CI with
supabase db advisors --fail-on erroragainst the local database.rls_disabled_in_publicflags exposed tables without RLS,rls_references_user_metadatapolicies that readuser_metadata,security_definer_view,function_search_path_mutableandanon_security_definer_function_executableviews and functions that bypass RLS,auth_rls_initplanpolicies that call auth functions once per row,auth_allow_anonymous_sign_insenabled anonymous sign-ins, andpublic_bucket_allows_listingpublic buckets whose files can be listed. ChecksSUPABASE-2, and partlySUPABASE-1,SUPABASE-3,SUPABASE-5,SUPABASE-6andSUPABASE-7. - 6
supabase test db: runs the pgTAP tests insupabase/testsagainst the local database, for example in a GitHub Actions workflow on every pull request. ChecksSUPABASE-4, and partlySUPABASE-1,SUPABASE-3,SUPABASE-6andSUPABASE-7, as far as the tests cover them. - 6 GitHub secret scanning push protection: blocks pushes that contain Supabase secret keys. Partly checks
SUPABASE-8.
Tutorials and further reading¶
- 6 Build a User Management App with React (Supabase): sign-up and sign-in, a profiles table protected by Row Level Security, and avatar uploads to Storage; the same tutorial exists for other frameworks.
- 6 Advanced pgTAP Testing (Supabase): test helpers from database.dev for creating users, switching roles and checking RLS across a schema, with a multi-tenant example.
- 6 Row Level Security performance (Supabase): measuring the cost of policies and tuning policies that are already correct.