Documentation Index
Fetch the complete documentation index at: https://mintlify.com/danielpose1996-stack/ruedadeproyectos/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Security is paramount for an academic platform handling student and faculty data. RuedaPro UNIPAZ implements multiple layers of security through Supabase Row Level Security (RLS), authentication controls, input sanitization, and role-based access control.Security Architecture
The platformās security model follows these principles:- Defense in Depth: Multiple security layers (client-side validation, RLS policies, authentication)
- Least Privilege: Users only access data they need based on their role
- Public Transparency: Evaluated project results are publicly visible for transparency
- Zero Trust: All requests are authenticated and authorized, even from authenticated users
Row Level Security (RLS)
Supabase RLS policies enforce data access rules at the database level, making it impossible to bypass security through API manipulation.Understanding RLS Policies
RLS policies are SQL-based rules that filter database queries. They run on every SELECT, INSERT, UPDATE, and DELETE operation. Key Concepts:- authenticated: Users who have logged in through Supabase Auth
- anon: Unauthenticated public users (visitors)
- USING clause: Determines which rows are visible/accessible
- WITH CHECK clause: Validates rows before INSERT/UPDATE
Perfiles (User Profiles) Security
Theperfiles table stores user information and must be carefully protected.
- Public users cannot see profiles of students without evaluated projects
- Public users cannot see teacher profiles
- Public users cannot see admin profiles
- Personal information remains private until projects are evaluated
Evaluaciones (Evaluations) Security
Evaluation scores are sensitive during the evaluation period but become public after completion.- Prevents public access to scores while projects are being evaluated
- Allows transparency after evaluation completion
- Prevents score manipulation by limiting who can see partial results
Complete RLS Policy Script
The full security hardening script is located atsql/rls_security_hardening.sql:
Always test RLS policies thoroughly before deploying to production. Use Supabaseās policy testing tools or create test users with different roles.
Role-Based Access Control (RBAC)
RuedaPro UNIPAZ implements three user roles, each with specific permissions:Admin Role
Capabilities:- Create and manage all users (docentes and estudiantes)
- Create and manage all projects
- Assign docentes to evaluate projects
- Assign estudiantes to projects
- View all evaluations
- Change project status to āEvaluadoā
Docente (Teacher) Role
Capabilities:- View projects assigned to them for evaluation
- Submit evaluations for assigned projects
- View their own evaluation history
- Cannot create users or projects
- Cannot view other teachersā evaluations (unless admin)
Estudiante (Student) Role
Capabilities:- View projects they are associated with
- View evaluation results for their projects (when available)
- Cannot create, edit, or delete anything
- Cannot view other studentsā projects (unless public)
Authentication Security
User Metadata
Critical user information is stored in JWT user_metadata:- Store only essential identification data (name, role)
- Store sensitive data in the
perfilestable with proper RLS - Validate role on every privileged operation
- Never trust client-side role checks alone
Session Management
The application restores user sessions on page load:- Sessions are stored in browser localStorage by Supabase
- JWT tokens have expiration times
- Tokens are automatically refreshed by Supabase client
- Manual logout clears all session data
Password Security
Supabase handles password security:- Passwords are hashed using bcrypt
- Minimum password requirements can be configured in Supabase dashboard
- Password reset flows use secure email tokens
- Failed login attempts can be rate-limited
- Minimum password length: 10 characters
- Require uppercase, lowercase, and numbers
- Enable rate limiting on auth endpoints
- Set JWT expiration to 1 hour with auto-refresh
XSS Prevention
RuedaPro UNIPAZ includes a helper function to prevent Cross-Site Scripting attacks:When to Use escapeHTML
Always escape user-provided content:Content Security Policy (CSP)
Add a CSP header to your web server configuration:Credential Management
API Keys
Supabase Anon Key (config.js):
- Safe to expose in client-side code
- Protected by RLS policies
- Has limited permissions
- NEVER expose in client-side code
- Only use in server-side Edge Functions
- Has full database access, bypasses RLS
Environment Variables
For production, use environment variables instead of hardcoded keys:- Netlify: Site Settings > Environment Variables
- Vercel: Project Settings > Environment Variables
- Custom Server:
.envfile (never commit this)
Database Security Hardening
Beyond RLS policies, implement these database security measures:Enable RLS on All Tables
Restrict Table Permissions
By default, Supabase grants broad permissions. Restrict them:Add Database Constraints
Enforce data integrity at the database level:Audit Logging
Enable audit logging in Supabase:- Go to Project Settings > Database
- Enable Log Connections
- Enable Log Statements
- Review logs regularly in Logs section
- Unauthorized access attempts
- Unusual query patterns
- RLS policy violations
- Performance issues
Security Checklist
Before deploying to production:Authentication
- Service role key is NOT in client-side code
- Anon key is properly configured in
config.js - Public signups are disabled
- Email confirmation is enabled
- Password requirements are set (min 10 chars)
- JWT expiration is configured (1 hour recommended)
Row Level Security
- RLS is enabled on ALL tables
-
rls_security_hardening.sqlscript has been run - Policies have been tested with different user roles
- Public access is limited to evaluated projects only
- Authenticated users can only access their assigned data
Input Validation
-
escapeHTML()is used on all user-provided content - Form inputs have client-side validation
- Database constraints are in place
- File uploads (if any) are validated and sanitized
Credentials
- API keys are stored in environment variables
- No sensitive keys are committed to Git
-
.envfile is in.gitignore - HTTPS is enforced on production domain
Incident Response
If you suspect a security breach:Immediate Actions
-
Rotate all API keys:
- Go to Supabase Project Settings > API
- Click Refresh next to anon and service_role keys
- Update all deployed applications with new keys
-
Review audit logs:
- Check Supabase Logs for unusual activity
- Look for unauthorized access patterns
- Identify affected user accounts
-
Reset compromised accounts:
- Force password reset for affected users
- Review and revoke active sessions
- Check for unauthorized data modifications
Post-Incident
-
Analyze the breach:
- Determine how the breach occurred
- Identify which data was accessed
- Document the timeline of events
-
Patch vulnerabilities:
- Fix the security hole that was exploited
- Update RLS policies if needed
- Add additional validation
-
Notify affected parties:
- Inform users if their data was compromised
- Report to university administration
- Document lessons learned
Additional Resources
OWASP Top 10
Learn about the most critical web security risks
Supabase Security
Official Supabase RLS documentation
Web Security MDN
Comprehensive web security guide
JWT Best Practices
JSON Web Token security considerations
Security Audit Schedule
Maintain security through regular audits:- Weekly: Review Supabase audit logs
- Monthly: Check for outdated dependencies
- Quarterly: Full security assessment
- Annually: External security audit (if budget allows)
Security is an ongoing process, not a one-time setup. Stay informed about new vulnerabilities and keep your dependencies updated.