Most applications enforce permissions in the application. A user requests a record, the code checks whether they should see it, and returns it or refuses. This works, and it is the layer everyone builds.
Row-level security moves that decision into the database itself. The table refuses to return rows the current role should not see, regardless of what the query asked for.
That sounds redundant when the application already checks. Here is when it is not.
The three ways the application layer is bypassed
A missing check. Someone adds an endpoint, or a report, or an export, and forgets the filter that every other endpoint has. Nothing errors. The data simply comes out. This is the most common data leak in ordinary business software and it is always an omission, never an attack.
A key that escapes. Anything shipped to a browser or a mobile app is public, whatever the documentation calls it. An API key in a compiled app is one decompilation away from being a public key. If that key’s only protection is the application code, and someone talks to the database directly, there is no protection.
Direct access. Analytics tools, admin panels, a colleague with a database client, a background job written in a hurry. None of these go through your application, so none of them get your application’s checks — and they are where regulated data actually leaks, rather than through the infrastructure everyone is busy hardening.
Row-level security holds in all three cases, because the rule lives with the data rather than with the code that usually reads it. It is also what record-level access control under HIPAA asks for, and why retrofitting that onto a system built around page-level roles is expensive.
What it actually looks like
A policy is a condition attached to a table, evaluated per row, per role. Give
the anon role permission to insert into a leads table and nothing else, and a
public key can accept a contact form submission and cannot read a single row
back — including the ones it just wrote.
That property is what makes a public API key safe. It is not secret. It is bounded.
The mistake that undoes it
Enabling RLS on one table and not the others.
If a schema is exposed and nine of its ten tables have no policy, you have secured the table you were thinking about and published the rest. The one people regret is usually a finance table nobody considered part of the application.
Check every table in every exposed schema, not the one you just built.
The part that surprises people
Table owners bypass RLS. By default, the role that owns a table is not subject to its policies. This is deliberate — migrations and admin tooling need to work — but it means turning RLS on often changes nothing you can observe, because you are testing as the owner.
Test as the role that will actually be used. If you have not tried the query as
anon, you have not tested the policy. Use FORCE ROW LEVEL SECURITY if you
need owners subject to it too.
Adding it to something already running
Enable it table by table, starting with the ones holding data you would not want published. Write the policy, then verify by connecting as the restricted role and attempting exactly what an attacker would: read the table, read a neighbouring one, reach a different schema.
Do not trust that it works because it did not error. An RLS policy that returns zero rows and an RLS policy that was never applied both look like a working application, right up until they do not.
The honest cost
An afternoon on a small system, and a habit thereafter — every new table needs a policy, and the default should be deny.
Against a category of breach that requires no attacker at all, only a colleague adding an endpoint in a hurry, that is among the cheapest security work available to you.
We do security reviews on applications already in production — what is exposed, what would leak, and what to fix first. Tell us what you’re running.