Security Incident Report: Supabase RPC Function Vulnerability
Date Discovered: December 2, 2025Severity: 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 withSECURITY 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:SECURITY DEFINER- Causing them to run as thepostgressuperuser, bypassing all RLS policiesanonrole 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):- The
anonrole 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 theanon and PUBLIC roles for all affected functions. This ensures that:
- Unauthenticated users cannot call these functions via the REST API
- The functions can only be called by authenticated users or the service_role (for backend/cron operations)
- 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
Recommended Follow-up Actions
- Audit Supabase logs for suspicious RPC calls to these functions
- Review recent activity on user accounts for anomalies
- Monitor for any reports of unauthorized access
- Consider rotating any sensitive API keys if breach is suspected
Prevention Measures
Best Practices for Future Development
-
Default to SECURITY INVOKER
-
Restrict SECURITY DEFINER functions to service_role only
-
Add user_id validation for SECURITY DEFINER functions
-
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
- Supabase Security Best Practices
- PostgreSQL SECURITY DEFINER Documentation
- OWASP API Security Top 10
This report should be retained for compliance and audit purposes.