Firebase Security Rules for Vibe-Coded Apps: Why “Signed In” Is Not “Authorised”
Firebase is the other backend AI tools reach for by default, and it ships with the same trap as Supabase: the demo works because the security rules allow everything. If your Firestore or Realtime Database rules contain allow read, write: if true; — or a date-based “test mode” expiry the AI never replaced — anyone with your public config can read and rewrite your entire database from a browser console.
Firebase console → Firestore Database → Rules (and Realtime Database → Rules, and Storage → Rules — they’re separate). Look for if true, for if request.time < timestamp.date(...) (test mode — it either already expired and broke your app, or it hasn’t and you’re open), or for if request.auth != null on its own. That last one is the subtle one: it means any logged-in user can read every other user’s data.
Why “signed in” is not “authorised”
AI-generated rules love request.auth != null. It reads like security, and it does block anonymous visitors. But your app lets anyone sign up, so “any signed-in user” means “anyone who spent thirty seconds creating an account.” Real rules compare the user to the data: the document’s userId field must equal request.auth.uid. This is the Firebase form of the authorisation gap in the vibe coding security checklist, and the same fix we describe for Supabase RLS.
The rules almost every app needs
For the common shape — users, and documents that belong to users — the baseline Firestore rules look like this:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
function signedIn() { return request.auth != null; }
function isOwner(userId) { return signedIn() && request.auth.uid == userId; }
// Each user's own profile
match /users/{userId} {
allow read, update, delete: if isOwner(userId);
allow create: if isOwner(userId);
}
// Things that belong to a user, stored with a userId field
match /tasks/{taskId} {
allow read, update, delete: if isOwner(resource.data.userId);
allow create: if isOwner(request.resource.data.userId);
}
// Everything else: closed
match /{document=**} {
allow read, write: if false;
}
}
}
Three things the AI usually misses: create must check request.resource.data (the incoming document), not resource.data (which doesn’t exist yet); update should also stop a user changing userId to someone else’s (add request.resource.data.userId == resource.data.userId); and the closing deny-all match is what protects the collections you forgot about.
The checklist
if true and no expired test-mode dates anywhererequest.auth != nullmatch /{document=**} block with if false. Without it, a collection the AI added last week may have no rule at all — which in Firestore means denied, but in a rule set that starts permissive it often means open.request.resource.data.title is string && request.resource.data.title.size() < 200. Without this, the client can write anything — including fields your app trusts, like isAdmin or plan.users/{uid}.role can be updated by the user, everyone is an admin. Make privileged fields writable only from a Cloud Function using the Admin SDK, or use custom claims./uploads/{uid}/... with request.auth.uid == uid. A public bucket of profile documents is the same leak with a different URL.context.auth; HTTP functions get nothing unless you verify the ID token. AI-generated functions frequently skip this — the Admin SDK inside them bypasses every rule above.Tell the AI exactly this
“Rewrite the Firestore rules so every collection with a userId field is owner-only for read, update and delete, create checks request.resource.data.userId == request.auth.uid, updates can’t change userId, and there’s a deny-all catch-all. List any collection where owner-only doesn’t fit and stop so I can decide. Then write the equivalent Storage rules.” Then run check 8 yourself — the tool reports success either way.
If ownership isn’t a clean single field — teams, shared projects, roles — the rules need a membership lookup (exists(/databases/$(database)/documents/memberships/$(...))) and that’s a data-model question. It’s also the one check in the 12-point prototype audit that decides whether the fix is an afternoon or a re-spine.
FAQ
where('userId','==',uid) clause or a code path that should never have worked.Want the rules reviewed before someone else reads them?
Fixed-scope Firebase security review: Firestore, Realtime Database, Storage and Functions — with the two-user test done and the rules rewritten.
