Originally published at syedwaleednawaz.com
Enforcing tenant isolation and role permissions at the database level rather than trusting client-side logic.
1. The Vulnerability of Client-Side Authorization
In multi-tenant SaaS products—such as clinical hospital systems with multiple branch locations or enterprise retail suites—tenant isolation is a non-negotiable security requirement.
A novice architecture pattern is adding 'tenant_id' as a query parameter in Flutter client code: supabase.from('patients').select().eq('tenant_id', currentTenantId). This is fundamentally insecure. Any user with a modified APK or reverse-engineered JWT can modify the client-side query and read records belonging to rival tenants.
True multi-tenancy requires database-enforced security: PostgreSQL Row-Level Security (RLS). When RLS is active, the database engine itself rejects unauthorized queries, regardless of what the Flutter client requests.
Key Takeaway: Never trust the client to filter by tenant_id.…