How to Detect Missing RLS Policies Before Production
Catch RLS drift after dashboard changes, so no table reaches production unprotected.
npm install -g @akal/supaforge. A hosted dashboard is on the way - to hear when it opens.Why RLS Drift Happens
Policies are often written in the Dashboard SQL Editor during development and never make it into a migration. A table can then reach production with RLS enabled but missing the policy that lets users read their own rows - or with RLS off entirely, leaving it open to anyone holding the anon key.
CVE-2025-48757 showed this at scale: apps shipped to production with their data exposed because the RLS policies never got there.
What SupaForge Checks
The rls check compares both environments and reports:
- Missing policies - in the source but not the target. Critical.
- Changed policies - same name, but a different command, roles, permissive or restrictive type,
USINGorWITH CHECK. Critical. - Extra policies - in the target only. A warning; removing one is held back until you add
--allow-destructive. - RLS switched off on a table where the source has it on. Critical.
Expressions are compared as PostgreSQL stores them, so formatting differences don't count as drift.
A second check, rls-coverage, looks at the target on its own and lists every table with RLS off, whichever pair you diff. Its findings feed a separate posture score and only affect the exit code with --fail-on-posture.
Step 1 - Install and Configure
npm install -g @akal/supaforgeCreate supaforge.config.json with supaforge init, or by hand. The connection strings come from your project's Connect dialog in the Supabase dashboard; keep them in environment variables or a .env file.
{
"environments": {
"staging": {
"dbUrl": "$STAGING_DATABASE_URL",
"projectRef": "STAGING_REF",
"accessToken": "$SUPABASE_ACCESS_TOKEN"
},
"production": {
"dbUrl": "$PRODUCTION_DATABASE_URL",
"projectRef": "PROD_REF",
"accessToken": "$SUPABASE_ACCESS_TOKEN"
}
},
"source": "staging",
"target": "production"
}Step 2 - Run an RLS-Only Diff
supaforge diff --check=rls --detailEach finding names the table and policy, its severity, and the SQL that fixes the target:
✖ [CRITICAL] Missing RLS policy: Users can read own profile
Policy "Users can read own profile" on public.profiles exists in source
but is missing from target. This is a CVE-2025-48757 risk pattern.
SQL fix (UP):
CREATE POLICY "Users can read own profile"
ON "public"."profiles"
AS PERMISSIVE
FOR SELECT
TO "authenticated"
USING ((auth.uid() = id))
;Step 3 - Fix the Target
See the fixes in the order they would run, without running them:
supaforge diff --check=rls --apply --dry-runThen apply just the RLS fixes:
supaforge diff --check=rls --applyStep 4 - Add It to CI
--ci exits 1 on drift and annotates the pull request, so a missing policy fails the build before it reaches production:
- name: Check RLS drift
env:
STAGING_DATABASE_URL: ${{ secrets.STAGING_DATABASE_URL }}
PRODUCTION_DATABASE_URL: ${{ secrets.PRODUCTION_DATABASE_URL }}
run: npx @akal/supaforge diff --check=rls --ciSummary
RLS policies are the most security-critical part of a Supabase project. SupaForge finds policies that are missing, changed or extra, and tables left without RLS, and fixes the target with reviewed SQL - locally, in CI or on a schedule.
Ready to try SupaForge?
Install the CLI and run your first diff in a minute. Nothing is changed until you add --apply.
npm install -g @akal/supaforge