Don’t forget to fix Security Checker findingsMake sure to address Lovable’s built-in security checker findings before publishing your app online. The security checker automatically scans your application and provides valuable recommendations for improving security.
Understanding Lovable’s Architecture
Unless instructed otherwise, Lovable generates applications with the following architecture:- Frontend: TypeScript/React application
- Backend: Supabase Edge Functions (serverless functions)
- Database: Supabase (PostgreSQL with real-time capabilities)
Frontend Security: Never Trust Client-Side Code
The Golden Rule: Frontend Code is Public
All React code runs in the user’s browser and is inherently public. Users can inspect, modify, or bypass any frontend code. Therefore:- Never store secrets in frontend code - API keys, passwords, or sensitive configuration
- Never perform validation in frontend code - Client-side validation can be bypassed
- Never trust frontend data - Always validate on the edge functions’ side
Common Frontend Security Mistakes
Examples of Prompts for Validating and Enhancing Frontend Security
Backend Security: Move Business Logic to Edge Functions
Treat Edge Functions as Your API Layer
Supabase Edge Functions should contain all your business logic, validation, and sensitive operations:- Authentication and authorization
- Data validation and sanitization
- Business logic and workflows
- Integration with external services
- Sensitive data processing
Best Practices for Edge Functions
Think of edge functions as your application’s security guards and business managers. They handle all the important work that needs to be done safely, away from the public-facing parts of your app.What Edge Functions Should Handle
User Authentication & Authorization- Always verify that users are who they claim to be before allowing them to perform actions
- Check if users have the right permissions for specific operations
- Never trust that someone is logged in just because they say they are
- Check all incoming data to make sure it’s in the correct format
- Remove any potentially harmful content from user inputs
- Ensure data meets your business rules before processing it
- Handle complex business processes like order processing, payment calculations, or user registration
- Manage relationships between different pieces of data
- Coordinate multiple steps in a single operation
- Safely connect to third-party services like payment processors, email providers, or APIs
- Keep sensitive API keys and credentials secure
- Handle errors and timeouts gracefully
- Process personal information, financial data, or other sensitive content
- Apply encryption or other security measures when needed
- Log important events for security auditing
Security Benefits of Edge Functions
Isolation: Edge functions run in a secure environment separate from your frontend, making it much harder for attackers to access sensitive code or data. Centralized Security: All security checks happen in one place, making it easier to maintain and update security policies. No Client-Side Exposure: Sensitive business logic never reaches the user’s browser, where it could be viewed or modified. Consistent Validation: Every request goes through the same validation process, ensuring consistent security across your application.Example of Prompts for Secure Edge Functions
Database Security: Keep RLS Simple and Start Early
Row Level Security (RLS) in Lovable
Lovable automatically sets up basic RLS policies for your tables, but you should review and customize them based on your app’s security needs. Think of RLS as the rules that determine who can see and modify which pieces of data in your database. Early Review is Critical: It’s much easier to adjust RLS policies when your app is new rather than after users have already created data. Simple is Secure: Keep RLS policies simple and focused on data access, not complex business logic. Lovable’s default policies are usually a good starting point.Common RLS Patterns in Lovable Apps
Personal Data Protection- Users should only see their own profile, settings, and personal data
- Default pattern: “Users can only access their own data”
- Team members can see shared project data within their team
- Pattern: “Users can access data from teams they belong to”
- Public posts that anyone can read, but only owners can edit
- Pattern: “Anyone can read, only owners can modify”
- Company employees can access company data
- Pattern: “Users can access data from their organization”
Reviewing RLS in Your Lovable App
Check Your Tables- Review which tables have RLS enabled
- Verify that sensitive data tables are protected
- Ensure public data tables have appropriate read policies
- Verify users can only see their own data
- Test that shared data is accessible to the right people
- Confirm that public data is visible to everyone
- Tables without RLS enabled on sensitive data
- Overly permissive policies that expose too much data
- Missing policies for new tables or features
Prompt Examples for RLS Review
Quick RLS Checklist
- All sensitive tables have RLS enabled
- Users can only access their own personal data
- Shared data has appropriate access controls
- New tables automatically get RLS policies
- Policies are simple and easy to understand
Authentication Security: Avoid Local Storage
Never Use Local Storage for Sensitive Data
Local storage is accessible to any JavaScript code running on your domain and can be easily bypassed:- Never store authentication tokens in localStorage
- Never store sensitive user data in localStorage
- Never store API keys or secrets in localStorage
Secure Authentication Flow
Workspace Protection: Secure Internal Applications
Ensure that internal apps have Visibility set to Protected
For applications that should not be publicly accessible:- Make internal apps “Protected” in project dashboard
- Verify they are not published to the internet
- Use proper authentication for all internal tools
- Regularly audit access to protected applications
Security Best Practices Summary
Development Workflow
- Start with security in mind - Implement RLS and authentication from day one
- Use the security checker - Run Lovable’s security checker regularly
- Follow recommendations - Implement all security suggestions
- Test thoroughly - Verify security measures work as expected
- Document security decisions - Keep track of security choices and rationale
Regular Security Audits
- Review edge function permissions
- Audit RLS policies
- Check for exposed secrets
- Verify authentication flows
- Test access controls
Common Security Checklist
- No secrets in frontend code
- All validation in edge functions
- RLS policies implemented and tested
- Authentication using secure methods
- Internal apps properly protected
- Security checker run and recommendations followed
- Regular security reviews conducted
Using Lovable Security Checker
Lovable provides a built-in security checker to help identify potential security issues:- Run the security checker in your project dashboard
- Review all recommendations carefully
- Implement suggested fixes promptly
- Re-run the checker after making changes
- Document any exceptions with clear rationale