Security Architecture
Inspect Africa Pro applies defence-in-depth across every layer -- from HTTP headers and CAPTCHA at the edge, to per-tenant database isolation and cryptographic audit trails in the data layer.
Authentication
| Control | Implementation |
|---|---|
| Session tokens | Supabase JWT, RS256-signed, auto-refreshed via Supabase SSR helpers |
| CAPTCHA | Cloudflare Turnstile on sign-in and both forgot-password pages |
| Email OTP expiry | 30 minutes (Supabase dashboard: mailer_otp_exp = 1800) -- covers password-reset and sign-up confirmation links |
| Account lockout | 3 failed sign-in attempts triggers a 15-minute per-email lock. Tracked in login_attempts table (Supabase-backed -- works across all Vercel instances) |
| IP rate limit | 5 requests / 60 s on auth scope via rateLimitDB(). Fails closed on database outage. |
| Idle timeout | 30-minute inactivity shows 5-minute countdown warning, then signs the user out and redirects to /sign-in?reason=idle |
| MFA | Not yet implemented. Supabase supports TOTP-based MFA -- planned for a future release. |
| Password policy | Minimum 8 characters, requires lowercase + uppercase + digit + symbol. Supabase HaveIBeenPwned integration available on Pro plan. |
| Secure password change | Supabase "Secure password change" enabled -- requires current password; session must be recent (within 24 h) |
Authorisation & Tenant Isolation
| Control | Implementation |
|---|---|
| Row-Level Security | Enabled on every table. Policies restrict reads and writes to company_id = auth.uid() context |
| RBAC scopes | aviation:read, aviation:write, admin -- enforced by requirePermission() on every Route Handler |
| API guard | api-guard.ts + withPermission() wrapper -- scope check runs before any database access |
| Service-role key | Used server-side only (createSupabaseAdmin() -- synchronous, never exposed to the client bundle) |
| Enumeration protection | Forgot-password endpoint always returns 200 regardless of whether the email exists |
HTTP Security Headers
| Header | Value |
|---|---|
| Content-Security-Policy | Restricts script/style sources; blocks inline eval |
| Strict-Transport-Security | max-age=63072000; includeSubDomains; preload |
| X-Content-Type-Options | nosniff |
| X-Frame-Options | DENY |
| Referrer-Policy | strict-origin-when-cross-origin |
Audit Logging
Every mutation emits a row to the audit_logs table with actor_user_id, action (namespaced, e.g. wo.transition, amp.approve),entity_type, entity_id, and a metadata JSONB field capturing before/after state, licence numbers, and digital signatures. Approval workflows additionally hash the approval payload to create a tamper-evident record.
Dependency & Pipeline Controls
- Pre-commit hook blocks Unicode em-dashes and en-dashes in source files
pnpm exec tsc --noEmitmust pass with zero errors before every commit- No production data mutations outside of explicit, authorised API calls
- Service-role key and all secrets managed via environment variables -- never committed
SUPABASE_SERVICE_ROLE_KEYis never referenced in client-side code or the browser bundle