Row Level Security in Supabase is powerful but invisible when it fails. A missing policy does not throw an error — it returns an empty array. A permissive policy does not warn — it leaks every row. The only way to know your RLS is correct is to probe it before launch traffic arrives.
1. Default-deny on every table
If a table has no RLS policies and RLS is enabled, all queries return nothing. That is correct. The dangerous state is RLS disabled entirely — which means the anon key can read everything. Before launch, confirm every user-facing table has RLS enabled and at least one SELECT policy scoped to auth.uid().
2. INSERT policies that validate ownership
A common mistake is allowing any authenticated user to insert into any row. The policy should enforce that the user_id column matches auth.uid() on insert, not just on select. Without this, one user can write data attributed to another.
3. Service-role key never in the client
The service role bypasses all RLS. If it appears in a client bundle, source map, or environment variable exposed to the browser, your entire database is public. PreFlight scans your origin for leaked keys and flags this before launch.
4. UPDATE policies scoped to owned rows
Allow users to update only their own records. A policy like "using (auth.uid() = user_id)" on UPDATE prevents horizontal privilege escalation where one customer can modify another customer's data.
5. DELETE restricted or disabled
Most SaaS products should soft-delete. If you allow hard DELETE, scope it tightly. An open DELETE policy means any authenticated user can wipe rows they should not touch. Consider removing DELETE policies entirely and handling deletion through server-side functions.
6. JOIN-based data leaks
RLS applies per-table. If table A is locked down but table B references table A via a foreign key and table B has weaker policies, data can leak through the join. Audit every table in the relationship chain, not just the primary one.
7. Storage bucket policies
Supabase Storage has its own RLS layer. A public bucket means anyone with the URL can download. Private buckets need explicit policies for upload, download, and deletion. Check that user uploads are scoped to their own folder path.
8. Realtime subscriptions respect RLS
Supabase Realtime uses RLS to filter which rows are broadcast to which client. If your RLS is too permissive, users can subscribe to changes on rows they should not see. This is harder to catch manually — automated probing is the reliable path.
9. Edge Functions with service role
Edge Functions that use the service role client bypass RLS entirely. This is intentional for admin operations, but every function endpoint should validate the caller's identity independently. Do not rely on RLS when the function itself has god-mode access.
Automate the audit
PreFlight connects to your Supabase project and probes RLS behavior on every check run. It catches permissive policies, missing restrictions, exposed keys, and storage misconfigurations without you manually writing test queries. Run it before every launch and after every migration.
Expanded field note
A behavior-first Supabase RLS audit: the practical answer
RLS can fail silently through empty results, permissive policies, storage paths, or service-role bypasses. This guide is for teams using Supabase for multi-tenant data. Start by naming the failure you want to prevent and the customer or operator who would notice it first.
The useful scope is the role matrix for anonymous, authenticated, owner, and cross-tenant requests. That keeps the work concrete: you can choose a URL, provider, route, release, or data operation, observe it, and decide what to do when the observation does not match the expected contract.
What good looks like
read and write probes, policy scope, storage behavior, and a recorded schema context. A result is stronger when it preserves the input, environment, timestamp, expected behavior, observed behavior, and the next action. This lets a different person reproduce the finding without asking the original operator to reconstruct the entire context from memory.
policy text is an input; the user-visible behavior is the evidence. Keep the scope visible when sharing the result. A passing outside-in check can prove a reachable behavior at a point in time; it cannot silently become a guarantee about private code, every authenticated role, or every provider failure mode.
Frame the decision before you change anything
teams using Supabase for multi-tenant data usually do not need another dashboard full of disconnected warnings. They need a defensible answer to a narrower question: is the behavior that matters to the customer working in the environment that is about to change? Start there. If the answer is unclear, make the ambiguity part of the work instead of translating it into a green score.
The first useful boundary is the role matrix for anonymous, authenticated, owner, and cross-tenant requests. Write it down in the same language the team will use during the fix. Name the route, provider, release, role, data object, or browser action involved. Then write the expected behavior as a sentence that could be checked by another person. This turns a broad topic into a small contract and makes it easier to tell whether a failure is reproducible, transient, out of scope, or genuinely fixed.
A good scope also includes what the check does not attempt. Public observation is different from authenticated authorization testing. Provider reachability is different from a complete fulfillment path. A page that renders in a browser is not necessarily a page a crawler can index. Stating the limit early protects the reader from overconfidence and tells the operator when to add a deeper review.
Questions the result should answer
- What was tested? Identify the canonical URL, route, provider, account role, release, or customer action rather than describing the scope as “the site.”
- What should have happened? State the expected response, permission, side effect, delivery event, page directive, or recovery signal in plain language.
- What actually happened? Keep the observed status, safe error, response detail, timing context, or missing side effect without pasting credentials or customer data into the record.
- Why does it matter? Connect the observation to a customer, crawler, revenue, security, availability, or release decision so severity is not just a color.
- What happens next? Name the smallest reversible fix, the owner, the rerun, and the condition that will close the issue.
These questions are deliberately boring. Boring evidence is easier to compare, easier to hand off, and easier to defend later. It also gives an answer engine or a future teammate enough context to summarize the result without inventing a claim that the original check never made.
A sequence that holds up under pressure
- List every table and bucket a browser can reach.
- Test reads as an anonymous user and as two different authenticated owners.
- Test insert, update, and delete separately.
- Probe joins, storage folders, realtime subscriptions, and Edge Functions.
- Rerun after each migration and keep the policy version beside the result.
The important nuance is this: policy text is an input; the user-visible behavior is the evidence. That distinction matters because fast remediation can create a second problem: a broad header change can break a payment script, a credential rotation can break a cron worker, and a restrictive policy can make a valid customer path look like an outage.
Evidence to keep with the fix
| Record | Why it matters |
|---|---|
| Scope | The URL, role, provider, release, and limitation prevent a result from being reused outside the question it actually answered. |
| Before | The original failing observation, environment, and customer impact make the fix auditable. |
| Change | The code, configuration, provider setting, migration, or credential action that should alter the result. |
| After | A rerun against the same scope proves whether the intended behavior recovered. |
| Owner | A named person or team, an expected next action, and a review date keep the result from becoming an orphaned warning. |
| Follow-up | An owner, cadence, or release rule keeps the same class of failure from returning silently. |
Failure modes worth checking twice
- RLS is enabled on one table while a related table remains permissive.
- A service-role client is accidentally bundled in the browser.
- Storage is public because the database table is protected.
- A policy passes for the owner but lets one tenant infer another tenant's records.
When one of these appears, avoid making several unrelated changes at once. Preserve the failing evidence, isolate the smallest boundary that can explain it, make one reversible correction, and rerun. That rhythm is slower than guessing for the first five minutes and faster than untangling a release that changed three providers at once.
Know when the first layer is not enough
Automation is valuable because it is repeatable, but repeatability is not the same as depth. If the question involves complex authorization, tenant isolation, injection, business logic, a high-value asset, or an adversarial threat model, use the automated result as a map for a deeper review. Give the reviewer the scope, failed observation, relevant release context, and the boundary you want tested. Do not present a public scan as a certification or a substitute for professional security work.
The same rule applies to operations. A successful provider probe may prove that a credential can reach an API, but it may not prove that a webhook creates the correct entitlement. A healthy uptime response may prove reachability, but it may not prove that a signed-in customer can complete the task. Add the assertion or browser journey that matches the real risk, and keep the cheap signal for early warning.
Questions people ask after reading this
What is the fastest useful first step?
Choose one representative scope and write the expected result before running the tool. For this topic, that means the role matrix for anonymous, authenticated, owner, and cross-tenant requests. A small, explicit baseline is more useful than a large scan whose findings have no owner or decision attached.
What should I do when the result is green?
Keep the scope, timestamp, and limitation, then decide whether the result belongs in a release gate, monitor, report, or follow-up review. Green means the observed contract passed. It does not turn untested behavior into evidence.
What should I do when the result is red?
Read the evidence before changing configuration. Confirm the environment, reproduce the smallest failing behavior, assign the next action, and rerun after the fix. If the issue requires credentials, source access, or adversarial judgment, escalate it rather than hiding the gap behind a retry.
After the fix ships
Run the same check on the canonical production surface, not only on a local or preview environment. If the issue involved a provider, wait for the real callback or scheduled sample. If it involved search, confirm the HTML, canonical, robots, sitemap, and internal links agree. If it involved payments or access, verify the side effect a customer receives rather than stopping at a browser redirect.
PreFlight is designed for this last step: keep the original observation, connect the relevant provider or journey, attach the release context, and let the next run show whether the system stayed healthy. The goal is not a bigger report. It is a shorter path from signal to a verified decision.
