Guides · BossCheck team · Updated 2026-10-14

Firebase and Supabase Security Rules for Multiplayer Games

With Firebase and Supabase, your game client talks to the database directly. That means your security rules are the only thing between players and your entire database.

Why this matters more for games

A Firebase config or Supabase anon key is meant to be public, and it ships inside your client. That's by design. What protects your data is Firebase Security Rules or Supabase Row Level Security (RLS). If those are open, any player can open the browser console or a REST client and read every save, edit their coins, or wipe the leaderboard.

AI coding tools often create the database in "test mode" or leave tables without RLS just to get things working. Firebase test mode rules allow open access until an expiry date, and a Supabase table without RLS enabled can be read and written by anyone holding the anon key through the auto-generated API.

Firestore: lock down player data

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    // Default: deny everything not matched below
    match /{document=**} { allow read, write: if false; }

    // Players can read and edit only their own profile, and only safe fields
    match /players/{uid} {
      allow read: if request.auth != null && request.auth.uid == uid;
      allow create: if request.auth != null && request.auth.uid == uid
        && request.resource.data.keys().hasOnly(['displayName', 'avatar', 'settings']);
      allow update: if request.auth != null && request.auth.uid == uid
        && request.resource.data.diff(resource.data).affectedKeys()
             .hasOnly(['displayName', 'avatar', 'settings']);
    }

    // Leaderboard: anyone signed in can read, nobody writes from the client
    match /leaderboard/{entry} {
      allow read: if request.auth != null;
      allow write: if false; // written by a Cloud Function after validating the match
    }
  }
}

Note the hasOnly checks. On update, request.resource.data is the whole document after the write, so the rule uses diff().affectedKeys() to look only at the fields being changed. Without it, a player could write coins: 999999 into their own profile. Currency, XP, inventory and scores should be changed by server code (Cloud Functions using the Admin SDK, which bypasses rules), not by the client.

Supabase: enable RLS on every table

-- Turn on RLS (no policies = no access via the anon/authenticated keys)
alter table public.profiles enable row level security;
alter table public.scores   enable row level security;

-- Players read and update only their own profile
create policy "own profile read" on public.profiles
  for select to authenticated using ( (select auth.uid()) = id );
create policy "own profile update" on public.profiles
  for update to authenticated
  using ( (select auth.uid()) = id ) with check ( (select auth.uid()) = id );

-- Scores are readable by everyone, but there is no insert policy:
-- only an Edge Function using the service_role key can write them.
create policy "scores readable" on public.scores
  for select using ( true );

Enabling RLS isn't the whole job on newer projects. Supabase's RLS docs warn that tables can start with full privileges granted to anon and authenticated, and adding policies doesn't remove those grants, so also run revoke all on table public.scores from anon, authenticated; and grant back only what each role needs.

RLS policies decide which rows a user can touch, not which columns. To stop players editing a coins column on their own row, keep currency in a separate table with no client write policy, or use column-level privileges (revoke update (coins) on profiles from authenticated).

Keys: what's public and what isn't

Realtime and multiplayer channels

Firebase Realtime Database has its own rules language (separate from Firestore), so check both if you use both. Supabase Realtime database-change events respect RLS, and Broadcast/Presence channels can be restricted with Realtime Authorization: write RLS policies on realtime.messages, join channels with { config: { private: true } }, and turn off "Allow public access" in Realtime Settings so only private channels are allowed. Don't assume a lobby is private just because its ID is random.

Test your rules

Want this checked automatically?

BossCheck is a security scanner for indie games built with AI tools. It's in pre-launch: join the waitlist for early access.

Join the waitlist →

FAQ

Is it safe that my Firebase API key is visible in my game?

Yes. The Firebase web API key identifies your project and is meant to be public. Your security rules, plus App Check if you add it, are what protect your data.

Is the Supabase anon key a secret?

No. It is designed to be used in clients, and RLS policies control what it can do. The service_role key is the secret one and must never ship in a game.

Should players write their own scores to the database?

No. Have the client submit the match result to a server function that validates it, then writes the score with admin privileges.

What happens if I enable RLS with no policies?

All access through the anon and authenticated keys is denied for that table. That is a safe default you can open up policy by policy.

More guides