Lovable + Firebase Security Blueprint

To secure a Lovable + Firebase stack, swap the test-mode Firestore rules for real ones and write Storage rules if users upload files. Then add your production domain to Firebase Auth and run every rule through the Firebase Emulator before launch. This blueprint covers Firestore, Storage, and Auth.

Setup Time1-2 hours

TL;DR

Lovable can generate a Firebase app that still runs on test-mode security rules, which let anyone read and write your database. Fix that first. Then set your Auth domains, check Storage rules if you take uploads, and test it all in the Firebase Emulator before you go live.

Part 1: Firebase Firestore Security Rules

This is the part that matters most. The users and private blocks lock each document to the signed-in user who owns it. Posts are public to read but only writable by their author.

Replace test mode rules
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    // User documents
    match /users/{userId} {
      allow read, update, delete: if request.auth != null
        && request.auth.uid == userId;
      allow create: if request.auth != null;
    }

    // User content
    match /posts/{postId} {
      allow read: if true;
      allow create: if request.auth != null
        && request.resource.data.authorId == request.auth.uid;
      allow update, delete: if request.auth != null
        && resource.data.authorId == request.auth.uid;
    }

    // Private user data
    match /private/{userId}/{document=**} {
      allow read, write: if request.auth != null
        && request.auth.uid == userId;
    }
  }
}

Part 2: Firebase Storage Rules

Skip this if your app doesn't take uploads. If it does, each user can only write to their own folder, any signed-in user can read, and files are capped at 5 MB.

storage.rules
rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /users/{userId}/{allPaths=**} {
      allow read: if request.auth != null;
      allow write: if request.auth != null
        && request.auth.uid == userId
        && request.resource.size < 5 * 1024 * 1024;
    }
  }
}

Part 3: Firebase Auth Configuration

In Firebase Console → Authentication → Settings:

  • Add your production domain to authorized domains
  • Configure OAuth redirect URIs
  • Review sign-in methods enabled

Security Checklist

Pre-Launch Checklist for Lovable + Firebase

Is the Firebase apiKey safe to expose?

Yes. The client-side Firebase config is meant to be public. Your security comes from Firestore and Storage rules, and hiding these values won't protect you.

Alternative Stack Options

Same idea, different stack:

Built with Lovable + Firebase?

Scan for insecure rules and auth issues.

Security Blueprints

Lovable + Firebase Security Blueprint