-- Finding: A-05. Layer 2 of tenant isolation: Postgres row-level security. -- Even if application code forgets a filter, the database refuses cross-tenant rows. -- The app connects as `app_user` (not the table owner, which bypasses RLS by default). ALTER TABLE "Tenant" ENABLE ROW LEVEL SECURITY; ALTER TABLE "Tenant" FORCE ROW LEVEL SECURITY; ALTER TABLE "RentPayment" ENABLE ROW LEVEL SECURITY; ALTER TABLE "RentPayment" FORCE ROW LEVEL SECURITY; ALTER TABLE "Review" ENABLE ROW LEVEL SECURITY; ALTER TABLE "Review" FORCE ROW LEVEL SECURITY; -- current_setting(..., true) returns NULL when unset, and NULL never equals anything: -- a query without the tenant variable sees zero rows rather than all rows. CREATE POLICY tenant_isolation ON "Tenant" USING ("organizationId" = current_setting('app.org_id', true)) WITH CHECK ("organizationId" = current_setting('app.org_id', true)); CREATE POLICY tenant_isolation ON "RentPayment" USING ("organizationId" = current_setting('app.org_id', true)) WITH CHECK ("organizationId" = current_setting('app.org_id', true)); CREATE POLICY tenant_isolation ON "Review" USING ("organizationId" = current_setting('app.org_id', true)) WITH CHECK ("organizationId" = current_setting('app.org_id', true)); -- Tenant ID documents (TenantEase "ID verification") live in private object storage. -- The table stores only the object key; the app issues signed URLs valid for ~60 seconds -- after an authorize() check, and logs every issuance for audit.