Free Supabase RLS Policy Generator and Safety Checker (Lovable and Bolt)

By the PrototypeVerdict Test Team

Our Lovable and Bolt links are referral links: if you sign up through one, Lovable or Bolt may reward us, at no extra cost to you. How we make money.

← All free AI app builder tools

Pick a table and who should see its rows, and this page writes the Supabase Row Level Security SQL for you, plus a prompt you can paste into Lovable or Bolt. Already have policies your builder wrote? Paste them into the checker below to find the patterns that leak data or break sign-in. Everything runs in this browser tab.

Nothing leaves your browser. The page doesn’t connect to your database, doesn’t call Supabase or any AI service, and doesn’t save what you type. It writes standard Postgres and Supabase RLS templates and checks text patterns. It can’t see your live policies, and it isn’t a security audit.

Why this matters for AI-built apps: Bolt’s built-in database was Supabase-backed in our tests, and Lovable’s docs say its built-in backend uses Supabase’s open-source foundation, with an option to connect your own Supabase project. In our first Bolt test build, sign-in got stuck on the login screen with a 500 error caused by recursive RLS policies on the profiles table. Bolt fixed it by moving the admin check into a SECURITY DEFINER is_admin() function, and that one fix used about 84K tokens. The checker below flags that pattern before it costs you a fix.

1. Generate RLS policies

This generator needs JavaScript. Without it, use the examples in Supabase’s RLS docs and the pattern table further down this page.

2. Check SQL your builder wrote

Where to find the SQL: Bolt’s project download included Supabase migration files in our test. In Supabase, you can run and review SQL in the dashboard’s SQL Editor.

What the generated SQL does

Every line follows Supabase’s Row Level Security docs:

  • Turns RLS on with alter table ... enable row level security. Supabase’s docs warn that a table in an exposed schema without RLS is readable and writable by any role with a grant on it.
  • Revokes, then re-grants. On many Supabase projects, a new public table starts with every privilege granted to the anon and authenticated roles, and adding policies doesn’t take those grants back. The SQL revokes them and grants back only the operations you ticked. Not every project grants them automatically; on those, the revoke changes nothing.
  • Writes one policy per operation. Supabase’s docs say to write a separate policy for SELECT, INSERT, UPDATE and DELETE, because a FOR ALL policy hides which operation each rule was meant to cover.
  • Uses USING and WITH CHECK the way the docs do. USING decides which existing rows a user can read, update or delete. WITH CHECK decides what a new or updated row may look like, which stops a user from creating a row for someone else or reassigning it.
  • Names the role with to authenticated (or to anon, authenticated for public reads), so the policy doesn’t run for roles it wasn’t meant for.
  • Wraps auth.uid() in a select, as (select auth.uid()), which Supabase’s docs say lets Postgres evaluate it once per statement instead of once per row.
  • Indexes the filter columns, which Supabase’s docs recommend so policy checks don’t turn reads into full table scans.
  • Puts team and admin lookups in a security definer function in a private schema with set search_path = ''. That is the pattern Supabase’s docs give for avoiding recursive policies, and for keeping such functions out of schemas the API exposes.

The five access patterns

Pattern Who can read Who can create, edit and delete Typical use
Private: owner only Only the row’s owner Only the row’s owner Notes, drafts, a user’s own records
Public read, owner write Everyone, including signed-out visitors Only the row’s owner Published posts or listings meant to be public
Signed-in read, owner write Every signed-in user Only the row’s owner A members-only directory or feed
Team or org rows via a membership table Members of the row’s team Insert and edit: team members. Delete: only the row’s owner Shared projects in a team app
Admin only via a security definer helper Admins listed in a roles table Admins listed in a roles table Back-office tables, such as an admin’s client list

Two things we confirmed in our own tests of the generated SQL: in the team pattern, any team member can edit the team’s rows, including changing the owner column, but can’t move a row to a team they’re not in, and only the current owner can delete. In the admin pattern, the roles table can be read only by the user it describes, so assign admins from the Supabase SQL editor or a trusted server, never from the browser.

What the safety checker flags

Finding Why it matters Source
RLS disabled, or a table created without enabling it Any role with a grant can read and write the table. Supabase RLS docs
USING (true) or WITH CHECK (true) on INSERT, UPDATE, DELETE or FOR ALL Everyone the policy applies to can change every row. In our test, one signed-in user could edit another user’s row. Our Postgres 17 test
USING (true) on SELECT for signed-out visitors Every row is public. Fine only for public data. Supabase RLS docs
A policy that queries its own table Postgres raises 42P17, “infinite recursion detected in policy for relation”. We reproduced it for both a SELECT and an UPDATE policy. Our Postgres 17 test
A SELECT policy that calls a function, not security definer, that reads the same table The query fails. We got error 54001, “stack depth limit exceeded”. Our Postgres 17 test
Two tables whose SELECT policies read each other Postgres raises 42P17 for every role the policies apply to. Supabase RLS docs; our Postgres 17 test
INSERT policy without WITH CHECK, or with USING Without WITH CHECK, the policy blocked every insert in our test. With USING, Postgres rejects the statement. Our Postgres 17 test
Policy with no TO clause It applies to every role, including signed-out visitors. Supabase RLS docs
Policy that reads user_metadata Signed-in users can change their own user metadata, so it can’t be trusted for authorization. Supabase RLS docs
Security definer function without set search_path, or in the public schema A caller could hijack unqualified names, and a function in an exposed schema is callable over the API. Supabase RLS docs
View without security_invoker = true Views can bypass the RLS of the tables they read. Supabase RLS docs
Unwrapped auth.uid(), FOR ALL policies, UPDATE without WITH CHECK Notes, not errors: performance and clarity. Supabase RLS docs

How we tested this tool

We ran the page’s own JavaScript in Node and ran its SQL on a local Postgres 17 database set up to behave like Supabase: an auth.uid() stand-in, the anon and authenticated roles, and Supabase-style default grants. It was not a live Supabase project.

  • Every option combination (5 patterns, 2 owner columns, 15 sets of operations, and each option on and off): 1,200 SQL scripts, all ran without errors. Every one also re-ran cleanly with the drop-first option on, and the checker raised no “Fix” finding on any of them.
  • Behavior checks with two users, a third user outside the team, and a signed-out visitor, for each pattern and owner column, with grants on and off. For example, in the private pattern a user couldn’t read, edit or delete another user’s row, couldn’t create a row in someone else’s name, and couldn’t hand their own row to someone else.
  • Checker cases, each run on Postgres too where behavior matters, including the recursive profiles policy (error 42P17), the function version of it (error 54001), Supabase’s two-table example (42P17), and the security definer fixes for both (no error).

All checks passed on the final version of the page.

When this tool won’t help

  • It can’t see your database. Policies created in the dashboard, or earlier migrations you didn’t paste, aren’t checked. A clean result only means these patterns weren’t in the text you pasted.
  • Your data model is more complex than these five patterns. Rows owned by two users, roles stored in JWT claims, or multi-step permissions need hand-written policies. Supabase’s RLS docs cover rows shared by a buyer and a seller, and team checks with auth.jwt() and app_metadata.
  • The real test is two accounts. Before launch, sign in as two separate non-admin test accounts and confirm neither can see or change the other’s rows. Supabase’s docs also describe writing policy tests and running them with supabase test db.
  • Secret keys bypass RLS. A secret or service role key used without a user token skips every policy, so keep it out of the browser.

More checks to run before you publish are in our vibe coding security checklist and the vibe-coded app security check, which looks for leaked keys in your page source.

Building on one of them? Open Lovable → · Open Bolt →

FAQ

What is a Supabase RLS policy?

Row Level Security (RLS) is a Postgres feature that Supabase uses for authorization inside the database. Supabase’s RLS docs describe a policy as adding a WHERE clause to every query on a table: a SELECT policy using ( (select auth.uid()) = user_id ) means each signed-in user only gets their own rows.

Why does my app say “infinite recursion detected in policy for relation”?

A policy is reading the table it protects, or two tables’ policies read each other. Postgres raises error 42P17. We reproduced it on Postgres 17 with a profiles policy that looks up the caller’s role in profiles. The fix in Supabase’s RLS docs is to move the lookup into a security definer function in a private schema, with set search_path = ”. Paste your SQL into the checker above to find the policy.

Is USING (true) ever OK in a Supabase policy?

Only for reading data that is meant to be public. Supabase’s RLS docs say a policy with to anon using ( true ) gives every signed-out visitor read access to every row the role can reach. On INSERT, UPDATE or DELETE, an always-true policy lets anyone the policy applies to change every row.

Do I need WITH CHECK on an INSERT policy?

Yes. Supabase’s RLS docs say insert policies use WITH CHECK so a user can’t create a row that belongs to someone else. INSERT policies can’t have USING at all; Postgres rejects the statement. In our Postgres 17 test, an INSERT policy with no WITH CHECK blocked every insert.

Does this tool send my SQL anywhere?

No. The generator and the checker run as JavaScript in this browser tab. The page doesn’t connect to your database, doesn’t call Supabase or any AI service, and doesn’t store what you type.

Does RLS protect data from the service role or secret key?

No. Supabase’s RLS docs say a secret key authorizes access through the service_role role, which bypasses RLS when the request carries no user access token. Never put a secret key in the browser or in frontend code.