From supabase
RLS policy testing patterns for Supabase - automated test cases for Row Level Security enforcement, user isolation verification, multi-tenant security, and comprehensive security audit scripts. Use when testing RLS policies, validating user isolation, auditing Supabase security, verifying tenant isolation, testing row level security, running security tests, or when user mentions RLS testing, security validation, policy testing, or data leak prevention.
How this skill is triggered — by the user, by Claude, or both
Slash command
/supabase:skills/rls-test-patternsThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Comprehensive testing framework for Row Level Security (RLS) policies in Supabase. Catch security vulnerabilities before production with automated tests for user isolation, multi-tenant security, role-based access, and anonymous user restrictions.
README.mdexamples/ci-integration.mdexamples/common-vulnerabilities.mdexamples/testing-workflow.mdscripts/audit-rls-coverage.shscripts/run-all-rls-tests.shscripts/test-anonymous-access.shscripts/test-multi-tenant-isolation.shscripts/test-role-permissions.shscripts/test-user-isolation.shtemplates/rls-test-suite.tstemplates/security-checklist.mdtemplates/test-scenarios.jsontemplates/user-isolation-tests.sqlComprehensive testing framework for Row Level Security (RLS) policies in Supabase. Catch security vulnerabilities before production with automated tests for user isolation, multi-tenant security, role-based access, and anonymous user restrictions.
Verify users can only access their own data:
# Test user isolation on specific tables
bash scripts/test-user-isolation.sh conversations messages profiles
# Test with specific user IDs
bash scripts/test-user-isolation.sh documents --user1 "uuid1" --user2 "uuid2"
# Generate detailed report
bash scripts/test-user-isolation.sh --all --report isolation-report.md
What it tests:
Verify organization/team data separation:
# Test organization isolation
bash scripts/test-multi-tenant-isolation.sh organizations projects documents
# Test with specific org IDs
bash scripts/test-multi-tenant-isolation.sh --org1 "org-uuid-1" --org2 "org-uuid-2"
# Test member access patterns
bash scripts/test-multi-tenant-isolation.sh --test-members
What it tests:
Verify role-based access control:
# Test RBAC policies
bash scripts/test-role-permissions.sh admin_panel sensitive_data
# Test specific role hierarchy
bash scripts/test-role-permissions.sh --roles "admin,editor,viewer"
# Test permission escalation prevention
bash scripts/test-role-permissions.sh --test-escalation
What it tests:
Verify anonymous users are properly restricted:
# Test anonymous access on all public tables
bash scripts/test-anonymous-access.sh
# Test specific tables
bash scripts/test-anonymous-access.sh public_posts comments
# Test auth.uid() null handling
bash scripts/test-anonymous-access.sh --test-null-uid
What it tests:
Check all tables have proper RLS policies:
# Audit entire database
bash scripts/audit-rls-coverage.sh
# Audit specific schema
bash scripts/audit-rls-coverage.sh --schema public
# Generate compliance report
bash scripts/audit-rls-coverage.sh --report compliance-report.md --format markdown
What it checks:
Execute all RLS tests:
# Run all tests with default settings
bash scripts/run-all-rls-tests.sh
# Run with custom database URL
bash scripts/run-all-rls-tests.sh --db-url "postgresql://..."
# Run and generate comprehensive report
bash scripts/run-all-rls-tests.sh --report rls-test-results.json --verbose
# Run in CI/CD mode (exit 1 on any failure)
bash scripts/run-all-rls-tests.sh --ci --fail-fast
Test sequence:
Example 1: Testing Chat Application Security
# Test conversation isolation
bash scripts/test-user-isolation.sh conversations messages participants
# Output:
# ✓ User cannot read other user's conversations
# ✓ User cannot send messages to other user's conversations
# ✓ User cannot add participants to other user's conversations
# ✓ All isolation tests passed (12/12)
Example 2: Multi-Tenant SaaS Security Audit
# Full audit of multi-tenant application
bash scripts/test-multi-tenant-isolation.sh organizations projects documents embeddings
# Output:
# ✓ Org A users cannot access Org B projects
# ✓ Removed users lose access immediately
# ✓ Cross-org document access blocked
# ✓ Embeddings respect org boundaries
# ✓ All multi-tenant tests passed (24/24)
Example 3: CI/CD Integration
# In .github/workflows/security-tests.yml
- name: Run RLS Tests
run: |
bash scripts/run-all-rls-tests.sh \
--ci \
--fail-fast \
--report rls-results.json
- name: Upload Test Report
uses: actions/upload-artifact@v3
with:
name: rls-test-results
path: rls-results.json
Example 4: Pre-Production Security Check
# Complete security validation before deploy
bash scripts/audit-rls-coverage.sh --report audit.md
bash scripts/run-all-rls-tests.sh --verbose --report tests.json
# Review both reports before deploying
cat audit.md
cat tests.json
psql) installedRequired in .env file:
# Database connection
SUPABASE_DB_URL="postgresql://postgres:[password]@[host]:5432/postgres"
# API keys for client testing
SUPABASE_URL="https://[project-ref].supabase.co"
SUPABASE_ANON_KEY="eyJ..."
SUPABASE_SERVICE_KEY="eyJ..."
# Test user credentials (optional, for client tests)
TEST_USER_1_EMAIL="[email protected]"
TEST_USER_1_PASSWORD="testpass123"
TEST_USER_2_EMAIL="[email protected]"
TEST_USER_2_PASSWORD="testpass456"
Tests create and clean up their own data, but you can provide:
# Optional: Use existing test users
TEST_USER_1_ID="uuid-for-test-user-1"
TEST_USER_2_ID="uuid-for-test-user-2"
# Optional: Use existing test orgs
TEST_ORG_1_ID="uuid-for-test-org-1"
TEST_ORG_2_ID="uuid-for-test-org-2"
🔒 RLS Test Suite v1.0.0
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📊 Test Summary
Tables tested: 5
Total tests: 48
Passed: 48 ✓
Failed: 0
Duration: 12.3s
✅ All RLS policies working correctly!
🔒 RLS Test Suite v1.0.0
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
❌ SECURITY ISSUE DETECTED
Table: conversations
Test: User isolation - SELECT
Issue: User B could read User A's conversations
Expected: 0 rows
Actual: 5 rows
Recommendation: Add USING clause to SELECT policy:
USING (auth.uid() = user_id)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📊 Test Summary
Total tests: 48
Passed: 43 ✓
Failed: 5 ❌
❌ Critical security issues found. Do not deploy.
Integration Points:
/supabase:test-rls commandsupabase-security-auditor agentrls-templates skill (creates policies, this tests them)Best Practices:
npx claudepluginhub vanman2024/ai-dev-marketplace --plugin supabaseAudits Supabase Row Level Security policies across all tables. Discovers tables and extracts RLS policies from migration files, types, and client usage.
Row Level Security policy templates for Supabase - multi-tenant patterns, user isolation, role-based access, and secure-by-default configurations. Use when securing Supabase tables, implementing RLS policies, building multi-tenant AI apps, protecting user data, creating chat/RAG systems, or when user mentions row level security, RLS, Supabase security, tenant isolation, or data access policies.
Applies Supabase security best practices: anon/service_role key separation, RLS enforcement, JWT verification, API hardening. Use for securing projects, auditing keys, or production checklists.