Quick Answer
Supabase Row Level Security (RLS) is the Postgres feature that decides which rows each request is allowed to read or write. The publishable key, which replaced the older anon key, is designed to sit in public code, so RLS on every exposed table is the only lock between the open internet and your data. Enable it on every table, write one policy per role and action, and treat any table without a policy as a table without a door.
A Supabase app has no private API layer by default: the browser talks to Postgres through a public key, and Row Level Security is the only thing that says no. If a table in an exposed schema has RLS off and its grants intact, anyone who can read your front end can read that table.
Key Takeaways
- Supabase documents the publishable key as safe to expose in web pages, mobile apps, CLIs and source code, because it “only reaches what Row Level Security allows.”
- Its own guidance is blunt: enable RLS on every table in an exposed schema.
- Once RLS is on and no policy exists, no data is returned through the API to a publishable key until you write one.
- Views bypass RLS by default, because they are usually created by the postgres user. On Postgres 15 and later,
security_invoker = truefixes it. - A secret key bypasses RLS when the request carries no user access token, so it never belongs in a browser.
- Index every column a policy filters on, and wrap
auth.uid()in aselectso Postgres can cache the result per statement. - CVE-2025-48757, published by NVD on May 30, 2025, describes insufficient RLS policy in Lovable-generated sites that allowed unauthenticated reads and writes of database tables.
Table of Contents
- What Does Row Level Security Actually Do?
- Why Is the Public Key Public?
- What Happens When RLS Is Missing?
- How Do You Write Policies That Hold?
- Where Do Views and Secret Keys Break the Wall?
- What Does RLS Cost in Performance?
- The Counter-Case: When RLS Alone Is Not Enough
- Common Mistakes
- FAQ
- The Bottom Line
What Does Row Level Security Actually Do?
It attaches a rule to a table that Postgres evaluates on every row, for every request, before any data leaves the database.
Normal application security lives in code. A server receives a request, checks who is asking, queries the database, and returns what that user may see. Supabase removes that middle server for most reads and writes. The client library sends the query straight to the database through the auto-generated API, and the database itself has to be the checkpoint.
That is a different threat model, and it is worth saying plainly: the thing deciding access is not your application. It is a policy written in SQL, attached to a table, running inside Postgres.
Supabase’s documentation describes two roles that matter for client requests. The anon role is an unauthenticated request, where the user is not signed in. The authenticated role is a signed-in request. A policy names the role, the action (select, insert, update, delete) and the condition. If no policy matches, the row does not exist as far as that request is concerned.
Solomon put the structure into one line. Proverbs 25:28 compares a person without self-control to a city whose walls are broken through. A table without RLS is that city. The data is not stolen by cleverness. It is walked out through a gap nobody closed.
Why Is the Public Key Public?
Because the browser needs to talk to the database, and anything the browser holds, the visitor holds.
A common first reaction to a Supabase project is alarm: the key is sitting in the JavaScript bundle, anyone can copy it. That reaction is correct and also beside the point. Supabase’s API key documentation lists the publishable key as safe to expose in a web page, a mobile or desktop app, GitHub Actions, CLIs and source code. The reasoning it gives is that anyone can read a publishable key, so it only reaches what Row Level Security allows.
Read that again, because it moves the whole security question. The key is not a secret. It is an identity badge that says “this request comes from the public.” What that badge can touch is decided entirely by the policies behind it.
The same documentation is careful about limits. A publishable key does not protect against reverse engineering, inspecting network traffic in the browser, cross-site scripting, cross-site request forgery, phishing or man-in-the-middle attacks. RLS is not a force field. It is one control, and it is the one that decides what a public caller reaches.
The older anon key is documented as the legacy version of the publishable key, with low privileges. Treat them the same way. Public by design, harmless only while RLS is doing its job.
What Happens When RLS Is Missing?
An unlocked table in an exposed schema answers anyone who asks, and the asker does not need to break anything.
The clearest public case is CVE-2025-48757. The National Vulnerability Database published it on May 30, 2025, and describes insufficient database Row Level Security policy in the Lovable platform through April 15, 2025, which allowed remote, unauthenticated attackers to read or write arbitrary database tables on generated sites. The weakness is classified as CWE-863, incorrect authorization.
A correction to the way this story usually gets told. The headline version is “Lovable leaked its keys.” That is not what the record says. The keys in those apps were publishable keys, public by design. The failure was the layer behind them: tables without adequate policies. The vendor has disputed the classification, arguing that individual customers are responsible for protecting their own application data. Both readings point to the same operational fact. The generator can write the app. It cannot be trusted to be the final reviewer of access.
I use that case for one reason, not to pile onto a vendor. When an AI tool or a template scaffolds a backend in minutes, the speed removes the pause where a human used to ask “who can read this table?” The question has to be asked on purpose now.
| Table State | What an Anonymous Request Sees |
|---|---|
| RLS off, default grants intact | Everything the grants allow, including writes |
| RLS on, no policies | Nothing, until a policy is written |
| RLS on, select policy for the authenticated role only | Nothing for signed-out callers, own rows for signed-in users |
RLS on, but anon still granted insert and no restrictive check | Inserts may still succeed |
View created by the postgres user without security_invoker | The view ignores the base table’s policies |
The fourth row is the one that surprises people. Supabase’s documentation notes that a table protected only by policies can still let anon insert if the original grant was never revoked, and recommends revoking the default anon and authenticated grants where a project still carries them. Policies narrow access. They do not remove a grant that was never withdrawn.
How Do You Write Policies That Hold?
Enable RLS first, then write the narrowest policy that serves the real use case, one action at a time.
The setup is two statements. The first turns the lock on. The second hands out exactly one key.
alter table public.invoices enable row level security;
create policy "owners read their own invoices"
on public.invoices
for select
to authenticated
using ((select auth.uid()) = user_id);
Three habits keep policies honest.
First, name the role. A policy with no to clause applies to every role, which is rarely what you meant. Say to authenticated when the rule is for signed-in users, and say nothing about anon when the answer for signed-out callers is no.
Second, write one policy per action. A single broad “all” policy is easy to write and hard to audit. Separate select, insert, update and delete policies tell you exactly which door each one opens, and that is the document your future self will read at midnight.
Third, make new tables safe by default. Supabase documents event triggers as the route to enable RLS automatically on every new table. A rule that depends on someone remembering will fail the week they are busy. A rule that runs on its own will not.
The same principle sits under the rest of the stack I run. The automation layer lives on a server I control instead of a per-task platform. The publishing layer goes through an API I can call without a browser. Each time, the question is the same: what happens when nobody is watching? A security rule that needs a person awake is not a rule. It is a hope.
Where Do Views and Secret Keys Break the Wall?
RLS protects the table. Anything that reaches the table by another route needs its own protection.
There are two common bypass paths, and both are documented.
The first is the view. Supabase’s documentation states that views bypass RLS by default because they are usually created by the postgres user. On Postgres 15 and later, you set security_invoker = true on the view so it obeys the policies of the tables underneath. On older versions, the documented alternatives are to revoke access from anon and authenticated, or to place the view in a schema that is not exposed.
The second is the secret key. The documentation says a secret key bypasses RLS only when the request carries no user access token, and that it must never be used in the browser or exposed to customers. It also calls the JWT-based service_role key a legacy alternative. The rule I apply: secret keys live on a server, in environment variables, behind code I wrote and reviewed. If one appears in a front-end repository, rotate it before doing anything else.
If your stack was chosen so that leaving is a database dump, then the data layer is yours to protect, and these two paths are where it gets quietly undone.
What Does RLS Cost in Performance?
A policy runs against every row a query touches, so a careless policy turns a fast table into a slow one.
Supabase gives two specific instructions. Add an index on every column your policies filter on. And where a policy uses a function such as auth.uid(), wrap it in a select so Postgres can cache the result for the statement instead of calling the function once per row. That is why the example above reads (select auth.uid()) rather than auth.uid() bare.
Both fixes are cheap. Neither is optional on a table that will grow. A table with ten rows hides the problem. A table with ten million rows exposes it, usually in front of a customer.
The Counter-Case: When RLS Alone Is Not Enough
RLS answers “which rows,” not “which business rules,” and a few risks sit outside it entirely.
Row Level Security does not validate that an invoice total is positive, that a status moves in the right order, or that a user is allowed to perform an action that is legal on their own row but wrong for the business. Those rules belong in database constraints, functions or server code.
It also does not cover the limits Supabase lists for publishable keys: cross-site scripting, request forgery, phishing and traffic interception sit above the database. A policy cannot save a session that has already been stolen.
And there is a fair argument for the opposite architecture. If every request already passes through a server you control, using a secret key behind your own authorization code, RLS becomes a second lock instead of the first. That is a legitimate design, and often the right one for sensitive data. What would change my read: a workload where every access path is server side and audited, in which case RLS is a backstop worth keeping, not the primary control worth sweating over.
Common Mistakes
- Leaving RLS off on a table because “nobody knows the URL.” The API is auto-generated and the key is public. Enable RLS on every table in an exposed schema before the first row is written.
- Treating “RLS on” as “done.” With no policies, nothing is readable through the publishable key. With a sloppy policy, too much is. Test each role against each action.
- Forgetting the original grants. Policies do not remove a grant. Revoke default
anonandauthenticatedgrants where a project still has them. - Shipping a view over a protected table. Set
security_invoker = trueon Postgres 15 and later, or keep the view in an unexposed schema. - Putting the secret key in front-end code. It bypasses RLS when no user token is attached. Keep it server side and rotate it if it ever leaks.
- Filtering on unindexed columns. Index every column a policy reads, and wrap
auth.uid()in aselect.
FAQ
Is It Safe to Expose the Supabase Anon Key?
Yes, if Row Level Security is enabled and the policies are correct. Supabase documents the publishable key, and its legacy anon equivalent, as safe to expose in web pages, apps and source code, because it only reaches what RLS allows. The safety belongs to the policies, not the key. If a table has RLS off and its grants intact, the same public key can read it.
Is Row Level Security Enabled by Default in Supabase?
Do not assume it is. Supabase’s documentation tells you to enable RLS on every table in an exposed schema and points to event triggers for enabling it automatically on new tables, which means you should verify the state of each table yourself. Check the table list in your project and run the Supabase security advisor, then confirm with a request made as an anonymous caller.
What Happens If I Enable RLS Without Writing a Policy?
Nothing is accessible through the API to a publishable key until you create a policy. That is the safe failure. The table becomes unreadable instead of open. Then you add the narrowest policy that serves the real use case, one role and one action at a time.
Does the Service Role Key Respect RLS?
No. Supabase documents that a secret key bypasses RLS only when the request carries no user access token, and that it must never be used in the browser. Keep it in server-side environment variables. If it appears in client code or a public repository, rotate it immediately.
The Bottom Line
A Supabase app is secure in exactly the places where someone wrote a policy and tested it as an anonymous caller. The public key is not the weakness. The weakness is the table nobody locked.
Do three things this week. List every table in every exposed schema. Confirm RLS is on for each one. Then make the same request a stranger would make, with the publishable key and no sign-in, and read what comes back. What you do not yet know is what your generators, templates and tired late-night migrations created without telling you. That is the part the test exists to find.
Build the wall before the city has anything worth taking. A gate nobody checked is not a gate.
Sources
- Row Level Security, Supabase Docs: the enable-on-every-table rule, behavior with no policies, the
anonandauthenticatedroles, secret key bypass, view bypass andsecurity_invoker, and the performance guidance. Accessed November 16, 2026. - API Keys, Supabase Docs: publishable key safe to expose, its stated limits, and the legacy
anonkey. Accessed November 16, 2026. - CVE-2025-48757, National Vulnerability Database: insufficient RLS policy in Lovable through April 15, 2025, published May 30, 2025, with the vendor’s dispute noted. Details confirmed through a mirror of the NVD record, accessed November 16, 2026.
This is not legal, security or financial advice. Verify configuration against your own project and the current Supabase documentation before relying on it.
