Security Architecture
Quality Hub GINEZ implements a comprehensive security model with defense-in-depth strategy, combining client-side validation, server-side enforcement, and database-level access control.Authentication
Method: Email + Password
Authentication is handled by Supabase Auth with industry-standard security practices:PKCE Flow
Proof Key for Code Exchange (PKCE) provides CSRF protection:- Auth code is bound to a
code_verifieronly the original client knows - Prevents interception attacks
- No additional CSRF tokens needed
Session Management
- Storage: localStorage (browser default)
- Token Type: JWT with refresh tokens
- Auto-refresh: Tokens automatically refreshed before expiration
- Persistence: Sessions persist across browser sessions
Authentication Flow
User Approval
New users require approval before accessing the system:Authorization
Role-Based Access Control (RBAC)
The system implements RBAC with the following roles:User Roles
-
Admin (
is_admin: true)- Full system access
- User management
- View all records
- Edit any record
- Delete records
- Access audit logs
-
Regular User (
is_admin: false)- View own records only
- Create production records
- Edit own records
- View reports (aggregated data)
- Access catalog
- Edit own profile
Role Definition
Permission Matrix
| Module | User | Admin |
|---|---|---|
| View own records | ✅ | ✅ |
| View all records | ❌ | ✅ |
| Create records | ✅ | ✅ |
| Edit own records | ✅ | ✅ |
| Edit any record | ❌ | ✅ |
| Delete records | ❌ | ✅ |
| View reports | ✅ (aggregated) | ✅ (all) |
| Manage users | ❌ | ✅ |
| View audit logs | ❌ | ✅ |
| Access catalog | ✅ | ✅ |
Granular Permissions Hook
For advanced permission control:Row Level Security (RLS)
Database-Level Access Control
RLS policies are enforced at the PostgreSQL level, providing defense even if client code is compromised.Enable RLS
Policy: Users View Own Records
Policy: Admins View All Records
Policy: Users Insert Own Records
Policy: Users Update Own Records
Policy: Admins Update All Records
Policy: Admins Delete Records
How RLS Works
- Client makes request to Supabase
- JWT token included in Authorization header
- Supabase validates token and extracts
user_id - PostgreSQL applies RLS policies to filter/restrict data
- Only authorized rows returned to client
Benefits of RLS
- Defense in depth: Protection at database level
- Automatic enforcement: No way to bypass via client code
- Performance: Filtering happens at database level
- Consistency: Same rules apply to all access methods
Client-Side Validation
Zod Schemas
Client-side validation prevents malformed data from reaching the server:Validation Helper
Input Sanitization
All user inputs are sanitized to prevent injection attacks:Rate Limiting
Protect against brute force and DoS attacks:Security Headers
Next.js configuration with security headers:Environment Variables
Secure Configuration
Public vs. Private Variables
NEXT_PUBLIC_*variables are exposed to the browser- Non-prefixed variables are server-only
Audit Logging
Document access tracking:Data Privacy
Personal Data Handling
- Minimal collection: Only necessary data collected
- User consent: Email verification for changes
- Data retention: Historical records preserved for traceability
- User deletion: Soft delete preserves audit trail
GDPR Considerations
- Right to access: Users can view their profile
- Right to rectification: Users can edit their profile
- Right to erasure: Admin can deactivate accounts
- Data portability: Export functionality for user data
Security Checklist
- Authentication with JWT tokens
- PKCE flow for CSRF protection
- Row Level Security policies
- Role-based access control
- Client-side validation with Zod
- Input sanitization
- Rate limiting
- Security headers
- Environment variable protection
- Audit logging
- User approval workflow
- Two-factor authentication (future)
- API rate limiting at edge (future)
- Advanced threat detection (future)
