URL: /rules/security/supabase-rls

---
title: "Supabase Row Level Security off: tables the anon key can read"
description: "A Supabase table without Row Level Security answers anyone who holds the public anon key. squirrel counts the rows each table your code queries shows that key, with a HEAD request that reads no data."
---

## What an exposed Supabase table is

A Supabase app ships its project URL and its anon key to every visitor. That is by design: the anon key is public, and Row Level Security (RLS) policies decide what the anon role may read. A table with RLS turned off has no such policy, so the Supabase REST API answers its rows to anyone holding the anon key, which is anyone who opened your site.

It is one of the most common gaps in apps built quickly on Supabase, including apps generated by AI app builders: the table is created, the app works, and nobody turns RLS on. Profiles, orders and messages are then readable by anyone with a `curl` command.

## What squirrel checks

This is a probing rule, and a loud one: it sends requests to your Supabase project host, which is not the audited site. It runs only when [probing intensity](/configuration/security) is `aggressive`, only when the audit may request other hosts (not `--offline`, and external link checking on), and inside the shared probe budget. A cloud audit of a website whose ownership is not verified stays passive, so it never sends one.

<Warning>
`aggressive` is for sites you run: only use it on a website you own or are authorized to test. This rule sends your site's public anon key to your own Supabase project in `HEAD` requests, asking how many rows that key can see in each table. It never reads a row.
</Warning>

### Finding the project and key

Finding them sends no request. squirrel reads the scripts and inline scripts the crawl already fetched for:

- A project URL, `https://<ref>.supabase.co`, where `<ref>` is the 20-character project ref. Placeholder URLs such as `https://your-project.supabase.co` are ignored.
- An anon key: a JWT whose payload says `"iss": "supabase"` and `"role": "anon"`, names the project in `ref` and has not expired. It is sent only to the project it names. A `sb_publishable_` key is used only when the same script names exactly one project.
- A service-role key or a `sb_secret_` key is never used. It bypasses RLS, so a table answering it proves nothing. [`security/leaked-secrets`](/rules/security/leaked-secrets) reports those keys.

At most two projects are probed.

### Which tables are probed

Only the tables your own shipped code queries: `.from("todos").select(...)` and similar supabase-js chains, and `/rest/v1/<table>` URLs. No table name is guessed, so a project whose scripts name no table is not probed at all.

At most eight tables per project and ten requests per audit.

### What is sent

One request per table, to the project host only:

```text
HEAD https://<ref>.supabase.co/rest/v1/<table>
Prefer: count=exact
apikey: <the site's anon key>
Authorization: Bearer <the site's anon key>
```

A `HEAD` request has no response body. With `Prefer: count=exact`, the Supabase REST API reports in the `Content-Range` header how many rows the anon role can see, for example `0-24/25` or `*/0`. The request has no query string and selects no columns. squirrel never sends a `GET` to Supabase and never reads a response body, even if a server sends one. A publishable key is sent in `apikey` only. Requests carry no cookies and none of the audit's custom headers, and do not follow redirects. A project host that resolves to a private, link-local or metadata address is refused before anything is sent.

### How the answer is judged

Only the status, the `Content-Type` and the row total in `Content-Range` are used:

| Answer | Verdict |
|---|---|
| `2xx` with a total above zero | Exposed: the anon key can see that many rows |
| `429`, a bot challenge (`cf-mitigated: challenge`), or a `403` carrying WAF or challenge markers | Not checked, and no further request is sent this run |
| `401` or a plain `403` that is not an HTML page (Supabase answers a `42501` permission error with one of these) | Protected |
| `2xx` with a total of `0` (`*/0`) | Not exposed or empty: see below |
| `404` that is not an HTML page | The table does not exist |
| `401`, `403` or `404` with `Content-Type: text/html` (a block or error page from something in front of the API) | Not checked |
| Any other status, a `2xx` without a numeric total, a network error or a timeout | Not checked |

What a count can and cannot tell apart:

- A total above zero means the anon role can read rows. It cannot tell RLS off from an RLS policy that deliberately lets anyone read the table, such as a public `posts` table. Review each flagged table: if it is meant to be public, make sure the policy allows only the rows and columns you mean to publish.
- A total of zero cannot tell RLS hiding every row from an empty table. Either way nothing is readable now, so it is not flagged, but an empty table with RLS off becomes exposed as soon as rows arrive.

### Results

The rule emits checks named `supabase-rls`:

- Fail, one check per project, when one or more tables report rows. Message: `1 Supabase table(s) in abcdefghijklmnopqrst.supabase.co report rows to the site's public anon key: profiles. Row Level Security is off, or a policy lets anyone read them (counted with a HEAD request, no row read)`. Each exposed table is an item such as `profiles (42 row(s) visible to the anon key)`. No row, value or column name is fetched, so none is stored or reported.
- Pass only when every table the code names, in every project found, got a definite answer: protected, zero rows or missing. Message: `No Supabase table reported rows to the public anon key (4 table(s) probed in 1 project(s))`.
- Skipped, reason `probe-incomplete` (not checked), when any table got no definite answer: the project throttled or challenged a probe, a probe failed, answered with an HTML error page or had no usable total, the budget ran out partway, or a table or project was left out by the per-audit caps. Those tables may be readable, so the run is never a pass and never clears an earlier finding.
- Skipped, reason `not-applicable`, when the site's scripts hold no Supabase project with an anon key.
- Skipped, reason `probing-passive` or `probing-not-aggressive`, when probing is below `aggressive`. Nothing is sent.
- Skipped, reason `external-requests-off`, on an `--offline` audit or one with external link checking off. Nothing is sent.
- Skipped, reason `no-tables-in-code`, when the site uses Supabase but its scripts name no table. Nothing is sent.
- Skipped, reason `probe-budget`, when the shared probe budget ran out before the first request, or partway through with every answer before that definite and none exposed. A run cut short is never a pass.
- Skipped, reason `probe-errors`, when every request failed with a network error, a timeout or a refusal.
- Skipped, reason `probe-inconclusive`, when every table was probed and no answer had a status and row total the rule can judge.

### Tables that are meant to be public

A table you publish on purpose, such as a public `posts` table, still fails, because a count cannot tell an intended read policy from RLS left off. To waive it, add an [`[[ignore]]`](/configuration/ignore) entry that matches its item id (`<ref>.supabase.co/rest/v1/<table>`) by table name, and every other table keeps being checked:

```toml squirrel.toml
[[ignore]]
rule   = "security/supabase-rls"
items  = ["glob:*/rest/v1/posts"]
reason = "posts is public by design"
```

### Limits

Only the tables your code names are tried: an exposed table no script mentions is not found. A table that is readable only through a view or an RPC function is not tried. A count does not say which columns are readable. Inline scripts are read from pages kept in memory; a streamed audit reads the fetched script files.

## How to fix it

Turn on Row Level Security for every table in an exposed schema, then add policies that grant only what each role needs:

```sql
alter table public.profiles enable row level security;

create policy "Users read their own profile"
  on public.profiles for select
  using (auth.uid() = id);
```

With RLS on and no policy, the anon key reads nothing. Check the Supabase dashboard's Security Advisor for other tables without RLS. Treat rows that were exposed as already read: rotate anything sensitive they held.

| | |
|---|---|
| **Rule ID** | `security/supabase-rls` |
| **Category** | [Security](/rules/security) |
| **Scope** | Site-wide |
| **Severity** | error |
| **Weight** | 8/10 |

## Enable / disable

### Disable this rule

```toml squirrel.toml
[rules]
disable = ["security/supabase-rls"]
```

### Disable all Security rules

```toml squirrel.toml
[rules]
disable = ["security/*"]
```

### Enable only this rule

```toml squirrel.toml
[rules]
enable = ["security/supabase-rls"]
```

`enable` replaces the default `["*"]`, so this is the only rule selected. Leave `disable` out: a rule that matches any `disable` pattern is skipped even when `enable` names it. Only an `enabled` setting under a rule's own `[rule_options]` table overrides both lists.

## Check names by outcome

Each check name this rule can emit, by what it means to a tool comparing two audits. A **problem** check is a finding. A **clean** check says the rule ran over what it covers and found nothing; it clears the problem checks listed beside it, so a finding is fixed when the rule ran over the same scope and a clean check took its place. A **not checked** check says the rule did not evaluate, and never clears a finding.

{/* rule-checks:start */}

| Check name | Outcome | Clears |
| --- | --- | --- |
| `supabase-rls` | Problem |  |
| `supabase-rls` | Clean | `supabase-rls` |
| `supabase-rls` | Not checked |  |

{/* rule-checks:end */}

## Related rules

- [security/leaked-secrets](/rules/security/leaked-secrets): finds keys in your pages and scripts, including Supabase service-role keys that must never reach the browser.
- [security/graphql-introspection](/rules/security/graphql-introspection): another probe of an API the site exposes to every visitor.
