← All articles

Firebase and Supabase Security Misconfigurations That Leak Your Data

Firebase and Supabase apps leak data for the same underlying reason: the client talks to the database directly, so the only thing standing between any visitor and every row is your access rules. In Firebase that means Firebase Security Rules; in Supabase it means Postgres Row Level Security (RLS), so Supabase RLS security comes down to your policies. The common failures are rules left open from development, rules that check "is logged in" instead of "owns this record", tables with RLS disabled, views that bypass RLS, and admin keys shipped to the browser. Each is quick to test and usually quick to fix.

The public config key in your frontend is not the problem. Firebase says API keys for Firebase services "only identify your Firebase project and app" and that authorization is handled by Security Rules and App Check. Supabase describes its publishable key as one that "anyone can read" and that "only reaches what Row Level Security allows." Both platforms are designed on the assumption that attackers have your client key. Your rules have to hold up anyway.

Firebase security rules: the five mistakes that matter

1. Open access left over from development

When you create a database or storage bucket in the console, Firebase lets you choose Locked mode or Test mode, and test mode grants access to everyone. Firebase's own guide calls out the fully open rules below and warns that "anyone who guesses your project ID can steal, modify, or delete the data."

// Cloud Firestore: never ship this
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if true;
    }
  }
}

The Realtime Database equivalent is ".read": true, ".write": true at the root. Variants with a date condition (if request.time < timestamp.date(...)) are still open until that date passes.

2. auth != null as the only check

This rule looks secure, which is why it survives code review. For most data it isn't: Firebase's documentation lists rules that only check for a logged-in user as a known insecure pattern. If sign-up is open, anyone can create an account and read every document in the collection.

// Insecure: any signed-in user can read and write every user's data
match /users/{userId} {
  allow read, write: if request.auth != null;
}

Fix it by tying access to the document owner, the pattern Firebase recommends:

match /users/{userId} {
  allow read, update, delete: if request.auth != null && request.auth.uid == userId;
  allow create: if request.auth != null && request.auth.uid == userId;
}

3. Ownership checked on read but not on write

A rule like allow update: if request.auth.uid == resource.data.owner checks the existing document, but not the incoming one. A user can update their own document and set owner to someone else, or add role: "admin". Firebase's owner-only example checks both resource.data (the existing document) and request.resource.data (the new one) to prevent ownership changes. If you store roles in user documents, block clients from writing those fields entirely.

4. Realtime Database rule cascading

Realtime Database rules cascade: per Firebase, rules at a parent path override deeper ones, and a child rule "can only grant additional privileges." Writing ".read": false on /users/private does nothing if /users already has ".read": true.

5. Cloud Storage with open or auth != null rules

Storage rules get less attention than Firestore rules, but they hold uploaded IDs, invoices and profile photos. The same open and "any authenticated user" patterns apply. Scope paths by user ID (match /users/{userId}/{allPaths=**}) and check request.auth.uid == userId.

Testing Firebase rules from the outside

Run these only against projects you own. They're unauthenticated GET requests, the same thing an attacker would try first.

# Realtime Database: shallow=true lists top-level keys without downloading data
curl 'https://<your-db>.firebaseio.com/.json?shallow=true'

# Firestore: try to list a collection without a token
curl 'https://firestore.googleapis.com/v1/projects/<project-id>/databases/(default)/documents/users?pageSize=1'

A Permission denied / PERMISSION_DENIED response is what you want. Data in the response means anonymous read is open. The Realtime Database REST API works on any database URL with .json appended, and newer databases may use a regional firebasedatabase.app hostname, so check the URL in your config. For authenticated testing, use the Firebase emulator and rules unit tests in CI.

Supabase RLS security: where the data leaks

Supabase exposes tables through an auto-generated REST API (PostgREST). Supabase's docs are explicit: "A table in an exposed schema without RLS is readable and writable by any role with a grant on it."

1. RLS disabled on a table in public

Tables created through raw SQL or migrations don't always get RLS turned on. Supabase's Security Advisor flags this as "RLS Disabled in Public", and it's the finding to fix first. Check from the SQL editor:

-- Tables in the public schema with RLS turned off
select schemaname, tablename
from pg_tables
where schemaname = 'public' and rowsecurity = false;

Fix:

alter table public.profiles enable row level security;

create policy "Users read own profile"
on public.profiles for select
to authenticated
using ( (select auth.uid()) = id );

Enabling RLS with no policies denies access to the anon and authenticated roles, which is a safe default while you write policies. Supabase also recommends that projects which still grant anon and authenticated broad privileges by default revoke those grants, since "adding policies doesn't remove them."

2. Policies that are too broad

using (true) on a select policy, or to authenticated with no ownership condition, is the Postgres version of Firebase's auth != null. Review every policy:

select tablename, policyname, cmd, roles, qual, with_check
from pg_policies
where schemaname = 'public'
order by tablename;

Look for qual = 'true', select policies for anon on tables holding personal data, and UPDATE policies with no with_check. Without with check, a user who can update their row may be able to change user_id to someone else's.

3. Policies based on user_metadata

Supabase warns that RLS policies relying on the user_metadata claim can create security issues because users can modify it. Their linter explains it "is designed to be manipulated by the user themselves". A policy like auth.jwt() -> 'user_metadata' ->> 'role' = 'admin' lets any user make themselves admin. Store roles in app_metadata or a table users can't write to.

4. Views that bypass RLS

Per Supabase, "Views bypass RLS by default because they are usually created with the postgres user." A view over a protected table can expose every row the table's policies were meant to hide. On Postgres 15 and later, define views with security_invoker so the querying user's permissions apply:

alter view public.order_summary set (security_invoker = on);

security definer functions in an exposed schema carry a similar risk: Supabase notes they're callable over the Data API with the creator's privileges.

5. The secret or service_role key in the frontend

The secret key (and the legacy service_role key) bypasses Row Level Security. If it's in your JavaScript bundle, mobile app or a public repo, your policies don't matter. Supabase is deprecating the legacy anon and service_role keys in favor of publishable (sb_publishable_...) and secret (sb_secret_...) keys, which makes accidental exposure easier to spot in code review. Search your built assets for sb_secret_ and for JWTs whose payload has "role":"service_role". Our guide on scanning JavaScript bundles for leaked API keys covers how.

Testing Supabase from the outside

With your own project's publishable key (the one already in your frontend):

curl "https://<project-ref>.supabase.co/rest/v1/profiles?select=*&limit=1" \
  -H "apikey: <publishable-key>"

An empty array or permission error for a table that holds private data is what you want. Rows coming back mean anonymous reads are allowed. Repeat for each table, and again with a normal user's access token to test whether one user can read another's rows.

Side-by-side: same mistakes, different syntax

FailureFirebaseSupabase
Everything openallow read, write: if trueRLS disabled on table in public
Any logged-in userif request.auth != nullto authenticated using (true)
Owner can be reassignedNo check on request.resource.dataUPDATE policy without with check
User-controlled roleRole field writable by clientPolicy on user_metadata
Rules bypassedAdmin SDK credentials in clientSecret / service_role key in client, views without security_invoker

Checking automatically

Manual curl tests work for a handful of tables, but they don't catch the new table added next sprint. SecurityInfinity's Firebase Rules Check and Supabase RLS Audit (which checks PostgREST exposure and RLS policies) run against apps on domains you've verified you own. Checks are read-only, and the JS Secrets Scanner looks for keys like a leaked service role in your bundles. Each finding includes evidence and the exact remediation. These sit alongside the broader checks described in what a cloud vulnerability scanner should catch.

Rules that only check authentication, not ownership, are access-control bugs, the same class as IDOR. Automated scanning can catch open rules; checking whether user A can read user B's data across every role is where authenticated testing earns its cost. See authenticated vs unauthenticated penetration testing, or book our Authenticated Startup Pentest, which includes access-control, IDOR and business-logic review across every user role. To check your project now, start a free scan.

Frequently asked questions

Is it safe to expose my Firebase API key or Supabase anon key?

Yes, as long as your rules are correct. Firebase states its API keys only identify your project, with access enforced by Security Rules and App Check. Supabase's publishable (formerly anon) key is meant to be public and can only reach what RLS allows. The Supabase secret or service_role key is different: it bypasses RLS and must never be exposed.

How do I know if my Firebase database is publicly readable?

Send an unauthenticated request to your own database. For Realtime Database, request https://<db>.firebaseio.com/.json?shallow=true; for Firestore, request a collection through the Firestore REST API without a token. If you get data instead of a permission error, anyone can read it. Also review your rules for if true and rules that only check request.auth != null.

What happens if RLS is disabled on a Supabase table?

If the table is in an exposed schema such as public, any role with a grant on it can read and write it through the Data API, which typically includes anonymous visitors using your publishable key. Supabase's Security Advisor flags this. Enable RLS on every exposed table and add explicit policies for the access you intend.

Is request.auth != null enough for Firebase security rules?

Usually not. It only confirms the user is signed in, so if anyone can create an account, anyone can read and write that data. Restrict access to the owner by comparing request.auth.uid to the document's user ID, and validate incoming writes with request.resource.data.

Do Supabase views respect Row Level Security?

Not by default. Postgres views run with the permissions of the view's owner, which on Supabase is usually postgres, so they bypass RLS on the underlying tables. On Postgres 15 and later, set security_invoker = on on the view so the querying user's RLS policies apply.

Find what attackers can see, before they do.

AI pentesting agents test your web app, API and cloud, and every finding comes with evidence and a fix. First report in about 10 minutes.

Stay ahead of attackers.

New vulnerabilities, breach write-ups and practical fixes. A few emails a month.