Supabase RLS Generator

Generate row-level security policies and check a schema for tables left open.

  • Free
  • No sign-up
  • Your input stays in your browser

Import a plan

Built a permission matrix already? The RBAC Matrix Builder saves it in this browser, and this turns it into tables and roles here.

This tool’s Plan JSON, or a JSON export from the RBAC Matrix Builder. An import replaces the current plan.

Options

Who can do what

  • Click a cell: — → Yes → Own
  • Yes every row
  • Own rows they own

Rename a table and its columns right in the table; click a role’s name to rename or remove it. Your plan is saved in this browser only.

Checks on this plan

    Audit · Paid

    Want the whole setup checked?

    A review of your code, auth or AI setup, with clear findings on what to fix first.

    Starts with a free 30-minute intro call, or email hello@nestedbit.com.

    What RLS is in Supabase

    Row-level security (RLS) is a Postgres feature that decides, row by row, what each query may read and write. Supabase leans on it more than most apps do, because its Data API lets the browser query your database directly. The key your site ships to browsers, the publishable key (or the older anon key), is public by design. Anyone can copy it from your page and call the API. RLS is the only thing between that key and your data.

    Each request runs as a Postgres role. Signed-out visitors are anon, signed-in users are authenticated, and server code using a secret key (or the old service_role key) is service_role, which skips RLS entirely. That’s why a secret key must never reach a browser.

    With RLS off, a table in the public schema is open to anyone with the public key. With RLS on and no policies, nobody but server code can reach it. Policies open it up again, one command at a time.

    How a policy works

    A policy names a table, a command (select, insert, update or delete), the roles it applies to and a condition. using decides which existing rows a command can see or touch; with check decides which new or changed rows may be written. Postgres lets a row through if any permissive policy allows it, so one loose policy undoes every careful one beside it.

    The pattern behind most apps is each user owning their own rows:

    alter table public.notes enable row level security;
    
    create policy notes_select on public.notes for select
      to authenticated
      using ((select auth.uid()) = user_id);
    
    create policy notes_insert on public.notes for insert
      to authenticated
      with check ((select auth.uid()) = user_id);
    
    create policy notes_update on public.notes for update
      to authenticated
      using ((select auth.uid()) = user_id)
      with check ((select auth.uid()) = user_id);

    Three details in it matter more than they look:

    • to authenticated keeps signed-out visitors out of the policy entirely. A policy with no role applies to everyone, anon included.
    • (select auth.uid()) runs the lookup once per query instead of once per row. Supabase’s own linter flags the bare form, because it’s much slower on big tables.
    • The update policy checks both sides, so a user can’t move their row to someone else by changing user_id. Updates and deletes also only reach rows a select policy lets the user see.

    Supabase RLS policy examples

    Content anyone may read, such as published posts:

    create policy posts_select on public.posts for select
      to anon, authenticated
      using (true);

    Roles, such as an admin who may delete any project. Keep who holds which role in a table users can’t write, and read it through a security definer function in a schema the API doesn’t serve, so the policy doesn’t loop back on itself:

    create policy projects_delete on public.projects for delete
      to authenticated
      using ((select private.has_role(array['admin'])));

    Writes only from a session that passed multi-factor sign-in, added as a restrictive policy on top of the others:

    create policy notes_update_mfa on public.notes as restrictive for update
      to authenticated
      using ((select auth.jwt() ->> 'aal') = 'aal2')
      with check ((select auth.jwt() ->> 'aal') = 'aal2');

    Files in Storage, where each user uploads only into a folder named after their id:

    create policy avatars_own_insert on storage.objects for insert
      to authenticated
      with check (
        bucket_id = 'avatars'
        and (storage.foldername(name))[1] = (select auth.jwt() ->> 'sub')
      );

    The generator above writes all of these from a grid of who can do what, with the roles table, the helper function, indexes on the columns policies compare and the grants each table needs. Start from a template, or import a matrix from the RBAC Matrix Builder.

    The mistakes that leak data

    Leaks from Supabase apps rarely need a clever attack. Someone reads the public key from the page and asks the API for a table. In UpGuard’s study of Supabase apps, published on 14 October 2026, 16,326 databases exposed readable tables, and over half showed signs of personal data. The same pattern was behind CVE-2025-48757, filed against apps generated by Lovable, which Lovable disputes on the grounds that each customer owns their data protection.

    The checker looks for these, most serious first:

    • RLS left off on a table the API can reach, worst when it holds passwords, tokens or keys.
    • Policies that are always true for writes, such as using (true) on update or delete.
    • Policies that only check someone is signed in, such as auth.uid() is not null. If anyone can sign up, that’s anyone.
    • Roles read from user_metadata. Users can change their own user_metadata from the browser, so they can give themselves any role. Use app_metadata, which only server code sets, or a roles table.
    • Views without security_invoker, which run as their owner and skip the policies on the tables they read.
    • Security definer functions in public that anyone can call at /rest/v1/rpc/, with the owner’s rights. Revoking from public isn’t enough on Supabase: anon and authenticated hold their own grants.
    • Storage policies that only check the bucket, which let anyone list or upload every file in it.

    Most of these follow Supabase’s own database linter, so the results line up with the Security Advisor in your dashboard. The checker also explains each one and writes the SQL that fixes it.

    Grants come before policies

    A role needs a grant on a table before RLS is even asked. Supabase used to grant every new table in public to anon and authenticated automatically. Its changelog says that stopped for new projects from 30 May 2026 and for existing projects on 30 October 2026. Tables that already existed kept their grants. A new table now answers with a permission error until you grant it, which is why the SQL this tool writes grants each role exactly the commands its policies use, and nothing else.

    Test policies as each user

    The SQL Editor runs as an admin, so a query there shows every row whatever your policies say. To see what a user sees, switch role inside a transaction and set their id:

    begin;
    set local role authenticated;
    select set_config('request.jwt.claims', '{"sub":"<a user id>","role":"authenticated"}', true);
    select * from public.notes;  -- only that user's rows
    rollback;

    The “Test as each user” output writes one of these blocks for every kind of user in your plan, with what each query should return. Every block rolls back, so it changes nothing.

    Check a project you already have

    Switch to “Check my project” and paste your migrations, the output of supabase db dump, or, for apps built in Lovable, Bolt or the dashboard with no migration files, the result of one read-only query you run in the SQL Editor. It reads settings only: tables, grants, policies, views, functions and buckets, never your rows. Everything is checked in your browser.

    Supabase signs users in with JWTs, and claims such as aal and app_metadata are what policies read. To see what a session’s token actually carries, paste it into the JWT Security Inspector. When roles start multiplying, read RBAC vs ABAC for when to switch to rules over attributes.

    Questions

    Is it safe to paste my schema here?

    Yes. The check runs in your browser, and what you paste isn’t sent to NestedBit or anyone else, or stored. A schema holds table and policy definitions, not your rows, and the query for projects without migration files only reads settings. Remove anything secret a function body might hold before you paste it.

    How do I check an app built in Lovable or Bolt?

    Those apps often have no migration files. Copy the query from “Check my project”, run it in the Supabase SQL Editor, and paste the one value it returns. It lists tables, grants, policies, views, functions and Storage buckets, so the result is more complete than reading SQL.

    Is it safe to put the anon or publishable key in my frontend?

    Yes, it’s meant to be public, and anyone can read it from your page. That’s why RLS matters: with RLS off, that key reads and writes the whole table. The secret key, or the old service_role key, skips RLS and must only ever run on a server.

    What does the generated SQL change?

    It turns RLS on for each table in your plan, sets exactly the grants its policies need, and writes one policy per command. With roles, it creates a table of who holds which role and a helper function outside the API. By default it drops other policies on those tables first. It’s safe to run again after you change the plan.

    Why does my app get no rows, or a permission error, after turning RLS on?

    No rows means no policy lets that user read them: RLS denies by default. A permission error (42501) means the role has no grant on the table. Since October 2026 Supabase no longer grants new tables to the API roles automatically. Updates and deletes also do nothing on rows the user can’t select.

    Should roles go in user_metadata or app_metadata?

    Never user_metadata: users can change it themselves from the browser, so a policy that trusts it lets anyone give themselves a role. app_metadata is set only by server code. A roles table users can’t write, as this generator makes, also lets you change roles without waiting for a token to refresh.

    How is this different from Supabase’s Security Advisor?

    The checker follows the same database lints, plus a few the Advisor doesn’t run, such as writes that only check someone is signed in and Storage uploads open to everyone. It explains each finding in plain words, writes the SQL that fixes it, and works on migrations before they reach your project.

    Can I run these checks in CI?

    Yes. The same checks run on your migration files with npx @nestedbit/check rls supabase/migrations, or in GitHub Actions with nestedbit/check, which marks each finding on the pull request’s changed lines. Both are free and open source at github.com/nestedbit/check. They read files only: nothing connects to your database or reaches NestedBit.

    Does a clean result mean my project is secure?

    It means the database settings it can see don’t leave data open. It can’t see your app code, edge functions, a secret key leaked into the browser, or whether each policy matches what your business intends. Test policies as each user with the script the generator writes.