Works with the AI Agents you already use

    Supabase Security Audit: RLS, RPC and Key Leaks

    by Hayder Al-Hwaidi

    1

    Securing a Supabase project requires more than just ticking boxes in the dashboard.

    $7

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    Supabase Security Audit: RLS, RPC and Key Leaks

    Supabase Security Audit: RLS, RPC and Key Leaks

    Example session with this skill installed

    Audit my Supabase project before launch. It's a Next.js marketplace with listings, profiles and orders.

    • Read your context and instructions
    • Compiled the supabase security audit
    • Generated the document

    Supabase security audit: marketplace

    Ran the audit SQL, the code scan and the live probe with the anon key.

    Findings

    SeverityLocationWhat a stranger can doFix
    Criticallib/admin.ts:4SUPABASE_SERVICE_ROLE_KEY is read through NEXT_PUBLIC_SUPABASE_SERVICE_ROLE_KEY, so it ships in the browser bundle (found in .next/static/chunks/)Move the admin call to a server route; rotate the key in Dashboard > API keys
    Highpublic.ordersRLS is off. Probe read 3 of 1,214 orders with names and addressesEnable RLS + owner policies (migration below)
    Highpublic.listings.seller_phoneReadable by anon on every public listing (RLS is per row, not per column)Column grants: revoke table select, grant only public columns
    Highpublic.admin_stats()SECURITY DEFINER, no search_path, executable by anon. Probe called it and got revenue totalsset search_path = '', revoke execute from public, anon
    Mediumapp/search/page.tsx:18.or() filter built from the raw search string lets a crafted q rewrite the filterReplace with a search_listings(q) RPC with a typed parameter
    Lowbucket avatarsPublic, contains only avatarsIntended: no change

    Migration

    alter table public.orders enable row level security;
    create policy "buyer reads own orders" on public.orders
      for select to authenticated using ((select auth.uid()) = buyer_id);
    
    revoke select on public.listings from anon, authenticated;
    grant select (id, title, price, city, photos, created_at) on public.listings to anon, authenticated;
    
    alter function public.admin_stats() set search_path = '';
    revoke execute on function public.admin_stats() from public, anon;
    

    Re-test

    node scripts/rls-probe.mjs orders listings --rpc admin_stats
    

    Expected: orders 0 rows, listings without seller_phone, admin_stats blocked.

    Rotate the service_role key before deploying the fix: it has already been public.

    page.tsx

    PDF · document

    Generated

    Example file from a real run - the skill writes it into your workspace.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Securing a Supabase project requires more than just ticking boxes in the dashboard. If your RLS policies are weak or your client-side filters are improperly handled, anyone with your public anon key can scrape your entire database or escalate privileges.

    This skill audits your Supabase implementation across the database, server-side functions, and client-side code to identify data leaks before they are exploited.

    What it does

    • RLS validation identifies tables where Row Level Security is disabled or using overly permissive policies.
    • Function auditing scans RPCs for SECURITY DEFINER vulnerabilities and missing search_path definitions.
    • Injection detection greps through client code for unsafe use of .or(), .filter(), and raw SQL templates.
    • Key leak detection searches build artifacts and environment variables for exposed service_role keys.
    • Live probing simulates an unauthenticated attacker attempting to read private tables and call RPCs.

    How it works

    1. Analyze Security Advisor results to clear high-level dashboard warnings and schema configuration errors.
    2. Execute audit SQL to find specific tables, columns, and functions exposed to anon and authenticated roles.
    3. Scan the codebase using grep patterns to find filter injection risks and hardcoded secrets.
    4. Run the RLS probe script with the public key to verify that private data returns empty sets or errors.

    Why this beats prompting it yourself

    Generic security prompts often miss the nuances of PostgREST syntax and the specific ways SECURITY DEFINER functions bypass schema permissions. This skill uses a multi-stage approach that combines static SQL analysis with actual network probes, ensuring you catch what an LLM might hallucinate as "safe" logic.

    Use cases

    • Audit a new project for RLS gaps before moving from development to production.
    • Verify that private columns like email or phone are truly hidden from the public key.
    • Check Edge Functions and Next.js routes for leaked service_role credentials.
    • Test RPC security after adding complex database logic or views.

    Known limitations

    This skill requires the user to provide output from the Supabase Security Advisor or have access to run provided SQL and shell scripts. It cannot automatically rotate leaked keys.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 3 days ago

    Software
    Supabase project
    Optional
    Node.js 18+ (for the live probe)ripgrep (for the code scan)

    Permissions

    Terminal / Shell
    Read Files
    Network Access
    Environment Variables
    Write Files
    Listed3 days ago

    What's inside

    Frequently Asked Questions

    This skill identifies critical vulnerabilities such as tables with disabled Row Level Security, overly permissive policies that leak private data, and SECURITY DEFINER functions that lack proper search paths. It also scans for service role keys leaked in client bundles and potential SQL or filter injection risks in your code.

    You should provide the output from the Supabase Security Advisor or be prepared to run provided SQL queries and shell scripts against your database and codebase. The skill also utilizes a probe script that requires your Supabase URL and public anon key to simulate an external attack.

    You receive a detailed findings table sorted by severity that explains exactly what an unauthorized stranger can access or execute. For every identified risk, the skill provides the specific location, the potential impact, and the migration SQL needed to fix the hole.

    While this skill identifies leaked service role keys in your build artifacts or environment variables, it cannot automatically rotate those keys for you. It also requires manual execution of its provided SQL and scripts if your agent does not have direct database access.

    You can ask your agent to audit a new project for RLS gaps before moving to production or verify if specific private columns like emails are truly hidden from the public. It is also useful for checking Edge Functions and Next.js routes for leaked credentials after adding new database logic.

    New in Data & Databases

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Data & Databases.