In Supabase, your 'API' is actually PostgREST sitting on PostgreSQL. Learn how IDOR + data exposure + broken auth chain together for devastating attacks, and get our audit prompt to find these vulnerabilities.

Copy this prompt and use it with your AI coding assistant to find vulnerabilities.
**Context:** I am hardening my Supabase application against advanced attack chains. In Supabase, the API (PostgREST) is a direct reflection of the database schema. I need to ensure that a single vulnerability (like a leaky RLS policy) cannot be chained with others (like IDOR or excessive data exposure) to compromise the system. **Task:** Audit my SQL schema, RLS policies, and Database Functions for the following "Triple Threat" vulnerabilities: **1. IDOR & Enumeration Check:** * Identify any tables using `BigInt` or `Serial` (integer) primary keys instead of `UUID`. * For existing integer keys, suggest a migration to `UUID` or a strategy to mask them using a `hashid` or a Public View. **2. Excessive Data Exposure (PostgREST Scrubbing):** * Scan all tables for sensitive columns (e.g., `email`, `stripe_id`, `internal_notes`, `role`, `is_admin`). * For these tables, write the SQL to create a **Secure View** using `WITH (security_invoker = true)` that excludes these sensitive fields. * Provide the `REVOKE` and `GRANT` commands to ensure the `anon` and `authenticated` roles can only access the **View**, not the raw table. **3. RLS Policy & Logic Audit:** * Flag any RLS policies using `USING (true)` or `CHECK (true)`. * Verify that every policy involving a user check uses the cached pattern: `((select auth.uid()) = user_id)` for performance and accuracy. * Check all **Database Functions (RPCs)**: * Ensure they are defined with `SECURITY INVOKER` by default. * If `SECURITY DEFINER` is required, verify that `SET search_path = public` is present and that `auth.uid()` is manually checked inside the function body to prevent privilege escalation. **4. Schema Hygiene:** * Confirm all tables in the `public` schema have RLS enabled. * Check for any "Shadow Admin" functions that bypass RLS but are exposed to the `authenticated` role. **Output Requirement:** Provide a summary of found "holes" and the exact SQL migrations needed to fix them.