Skip to main content

Security Incident Report: Supabase RPC Function Vulnerability

Date Discovered: December 2, 2025
Severity: Critical
Status: Resolved
Report Author: Security Audit

Executive Summary

A security audit of Supabase RPC functions revealed a critical misconfiguration affecting 9 database functions. These functions were configured with SECURITY DEFINER mode while also granting execute permissions to the anon (anonymous) role. This combination allowed unauthenticated users to bypass Row Level Security (RLS) policies and potentially access, modify, or expose sensitive user data. The vulnerability was discovered through a systematic audit of all public schema functions and was immediately remediated by revoking inappropriate access permissions.

Vulnerability Details

Technical Background

Supabase/PostgreSQL functions can operate in two security modes:

The Problem

The affected functions were configured with:
  1. SECURITY DEFINER - Causing them to run as the postgres superuser, bypassing all RLS policies
  2. anon role had EXECUTE permission - Allowing unauthenticated API calls to invoke these functions

Attack Vector

An attacker could exploit this vulnerability with just the public Supabase anon key (which is exposed in frontend applications):
This would return all user data from the database, bypassing any RLS policies, because:
  • The anon role could call the function
  • The function ran as postgres (SECURITY DEFINER)
  • No authentication was required

Affected Functions

Critical Severity (Data Exposure Risk)

High Severity (Data Manipulation Risk)

Medium Severity (Data Integrity Risk)


The Fix

What Was Done

The fix involved revoking execute permissions from the anon and PUBLIC roles for all affected functions. This ensures that:
  1. Unauthenticated users cannot call these functions via the REST API
  2. The functions can only be called by authenticated users or the service_role (for backend/cron operations)
  3. RLS bypass is only possible through properly authenticated channels

SQL Commands Applied

Verification Query

After applying fixes, run this query to verify no vulnerable functions remain:

Impact Assessment

Potential Data Exposed

Based on the function capabilities, the following data categories could have been accessed:
  • ✅ User accounts and profiles
  • ✅ Bank account connections and balances
  • ✅ Investment holdings and positions
  • ✅ Transaction history
  • ✅ Physical asset records
  • ✅ Internal system data
  1. Audit Supabase logs for suspicious RPC calls to these functions
  2. Review recent activity on user accounts for anomalies
  3. Monitor for any reports of unauthorized access
  4. Consider rotating any sensitive API keys if breach is suspected

Prevention Measures

Best Practices for Future Development

  1. Default to SECURITY INVOKER
  2. Restrict SECURITY DEFINER functions to service_role only
  3. Add user_id validation for SECURITY DEFINER functions
  4. Regular security audits
    • Run the vulnerability detection query weekly
    • Review new functions before deployment
    • Document security mode choice for each function

Security Audit Query (Add to CI/CD)


Timeline


References


This report should be retained for compliance and audit purposes.