This page focuses on how to write secure code for Lovable apps and avoid common security mistakes during development. For details on Lovable’s security model, security scans, and findings, see Security overview, Project security view, and the Workspace security center.Documentation Index
Fetch the complete documentation index at: https://docs.lovable.dev/llms.txt
Use this file to discover all available pages before exploring further.
How Lovable apps are structured
Lovable apps are built with a clear separation of responsibilities:- Frontend runs in the user’s browser, is always public, and must never be trusted
- Edge Functions run server-side and handle validation, authentication, and business logic
- Database uses PostgreSQL with row-level security (RLS) to enforce data access
Frontend security basics
All frontend code runs in the user’s browser and can be inspected, modified, or bypassed. Frontend code should never make security decisions.Do not store secrets in frontend code
Secrets stored in frontend code are visible to users and should be considered compromised.Do not rely on frontend validation for security
Frontend validation improves user experience but provides no security guarantees.Backend security with Edge Functions
Edge Functions form the secure boundary between your public frontend and your private systems. They run in an isolated server-side environment where sensitive logic cannot be accessed or modified by users. Any logic that affects security, data integrity, or external services should run in Edge Functions, not in frontend components. Centralizing validation and authorization here ensures every request is evaluated consistently and prevents critical logic from reaching the browser. Edge Functions should handle:- Authentication and authorization
Verify who is making a request and whether they are allowed to perform the action. - Data validation and sanitization
Treat all input as untrusted and enforce business rules consistently. - Business logic and workflows
Handle multi-step processes like registrations, payments, approvals, and state transitions. - Integration with external services
Call third-party APIs securely and keep credentials out of the browser. - Sensitive data processing
Process personal or financial data safely, avoid exposing it unintentionally, and log important security events.
Database security with RLS
Row-level security (RLS) controls who can read or modify individual rows in your database. It acts as a final layer of protection, enforcing access rules even if frontend or backend logic fails. Lovable sets up basic RLS policies automatically, but you should review and adjust them early in development. RLS is much easier to change before real data exists, and policies are most effective when they stay focused on access control rather than complex business logic.Common RLS patterns
Most Lovable apps fit into a small set of access patterns:- Personal data: users can access only their own data
- Team-based access: team members share access to team data
- Public content with ownership: anyone can read, only owners can modify
- Organization-based access: users access data within their organization
RLS checks before publishing
Before going live, verify:- RLS is enabled on all sensitive tables
- Users cannot access other users’ private data
- Shared and public data behaves as intended
- New tables are not missing policies
Authentication security basics
All authentication decisions must happen server-side, not in the browser. Client-side authentication checks can be inspected, modified, or bypassed by users and should never be relied on for access control. Authentication should be enforced in Edge Functions, where sessions and tokens can be verified securely and consistently.- Validate authentication and session tokens in Edge Functions
- Check roles and permissions server-side
- Use built-in session management for secure token handling
- Redirect users to login when sessions expire, but always validate on the server first
- Use frontend auth state only to control UI, never to enforce access
Workspace security
For applications that should not be publicly accessible:- Set project access to workspace
- Verify the app is not published publicly
- Require authentication even for internal tools
- Regularly audit who has access
Security checklist before publishing
Before publishing your app, confirm:- No secrets exist in frontend code
- All validation and critical logic runs in Edge Functions
- Row-level security (RLS) policies are configured and tested
- Authentication is enforced server-side
- Internal apps have workspace visibility
- All critical findings in the Security view are addressed
- External API calls happen server-side