Deutsch
Security wikiPrinciples

What is the principle of least privilege?

Also known as: principle of least privilege, PoLP, minimal privilege, need to know

Least privilege means every user, key and process gets only the access it needs. What that looks like in a Supabase app, with a tested query of anon’s grants.

By Tim GeithnerUpdated 2 min read

Short answer

The principle of least privilege says every user, key and process should get only the access it needs for its job, and nothing more. In a Supabase app that means narrow grants for the anon and authenticated roles, policies on top, the secret key only where admin rights are unavoidable, and functions that run with the caller’s rights by default.

Ask an AI about this page:ChatGPTClaude

On this page

The principle of least privilege says that every user, key and process should be granted only the access it needs to do its job. NIST’s glossary defines it as a design in which each entity gets the minimum resources and authorizations required for its function. The opposite, running with more rights than needed, is a weakness of its own: CWE-250 (opens in a new tab), because extra privilege makes every other bug worse.

Least privilege in an AI-built app

Supabase projects used to start generous: new tables in the public schema were granted to the anon and authenticated roles automatically, so the only thing standing between a visitor and a table was row level security. Since 2026 Supabase no longer does that for new tables (the default for new projects since May 30, for all projects since October 30), but every table created before keeps its grants. AI builders add to that: they create tables with grant all … to anon, authenticated, use the service role key when a query fails, and mark functions security definer so they “just work”.

Least privilege turns each of those around:

ThingToo muchEnough
Visitors (anon)All privileges on every tableOnly select on public content tables
Signed-in usersdelete and truncate everywhereThe commands each table really needs, plus RLS
Browser keySecret / service role keyPublishable key
Server codeOne secret key shared everywhereOne secret key per component
Functionssecurity definer in publicsecurity invoker, execute only for roles that call it

How to check your app

See what a visitor without an account is allowed to do, table by table:

What can visitors without an account do?
select table_name,
       string_agg(privilege_type, ', ' order by privilege_type) as privileges
from information_schema.role_table_grants
where grantee = 'anon'
  and table_schema = 'public'
group by table_name
order by table_name;

Every table listed is reachable through the API without signing in, limited only by RLS. Run it again with grantee = 'authenticated'. Any DELETE, TRUNCATE or UPDATE that no feature needs is privilege you can take back.

How to fix or prevent it

Take back what isn’t needed and grant only what is. For a private invoices table:

SafeNarrow grants for one table
revoke all on table public.invoices from anon, authenticated;
grant select, insert, update on table public.invoices to authenticated;

Keep RLS on as well: grants decide which commands a role may run, policies decide which rows. For functions, see SECURITY DEFINER; for roles inside your app, such as admins and viewers, read Roles and permissions in Supabase. Keys that ended up in the browser are covered in service_role key in the frontend.

Frequently asked questions

If I have RLS, do grants still matter?

Yes. Grants decide whether a role may use a table or command at all; RLS then decides which rows. Revoking what a role never needs is a second lock that still holds if a policy is wrong.

Does least privilege apply to API keys too?

Yes. Use the publishable key in the browser, a separate secret key per back-end component, and restricted keys where a provider offers them, such as Stripe’s restricted API keys.

Is it least privilege to give the AI builder full access to my project?

Give tools the access the task needs. For a review, read-only access is enough; for changes, prefer a reviewable pull request over direct write access to production.

Sources

  1. 1.Breaking change: tables not exposed to the Data API and GraphQL API automatically — Supabase Changelog
  2. 2.Least privilege (glossary) — NIST CSRC
  3. 3.CWE-250: Execution with Unnecessary Privileges — MITRE
  4. 4.GRANT — PostgreSQL Documentation
  5. 5.Securing your API — Supabase Docs
  6. 6.Best practices for managing secret API keys — Stripe Docs

Find this in your own app

ShipRely reads your repository (read-only), proves each finding with file and line, and gives you a fix prompt to paste into your AI builder.

Run a demo audit
  • Read-only access to your repository
  • Every finding with file and line
  • Fix prompts for Lovable, Cursor, Claude Code and Bolt