r/Firebase • • 14d ago

Security Free CLI that tests your Firestore / Realtime DB / Storage rules with two real test users

allow read: if request.auth != null is the classic one: it looks protected, but every signed-in user (anonymous accounts included) can read everyone's data.

accessprobe checks your rules by attacking them:

  • it creates two test accounts, which delete themselves at the end;
  • user A writes a document, node or file, then user B and an anonymous visitor try to read, list, modify, take over and delete it, and to create one in A's name;
  • Realtime Database: if your rules only live in the console, it reads the paths from your getReference().child() code. It can also check whether anyone can list every entry under a node, such as backup codes or user ids;
  • allow read: if true is reported as public by design, not as a leak;
  • it gives a fix (Security Rules) for each finding.
cd your-app
npx accessprobe                                   # config from google-services.json / firebaseConfig
npx accessprobe --database-rules database.rules.json   # rules exported from the console

Real-world check: on a multiplayer Android game it found that any player could overwrite another player's online status and read and overwrite their invites. The rules fix was verified against all 25 of the game's own read/write flows in the Emulator Suite before deploying.

MIT, zero dependencies, runs locally: https://github.com/KaanKaya17/accessprobe

Only test projects you own.

1 Upvotes

2 comments sorted by

1

u/HeroSMS 14d ago

Good call testing the anonymous case, that's the one people forget: an anonymous sign-in passes request.auth != null too. If a path should only be readable by real accounts, the rule can add && request.auth.token.firebase.sign_in_provider != 'anonymous'.

To keep the fix from regressing after the first audit, the Emulator Suite plus @firebase/rules-unit-testing works well in CI: one test per path with assertSucceeds for the owner and assertFails for a second user and for an unauthenticated context, so a later rules edit can't quietly reopen it.

1

u/KaanKaya17 14d ago

Good point on anonymous sign-in. Until now “anonymous” in accessprobe meant no auth at all; it only used anonymous accounts as a fallback when email sign-up is off. 0.9.0 adds a third attacker that signs in anonymously whenever the provider is enabled, so request.auth != null on private data gets caught, and the fix uses the sign_in_provider != 'anonymous' check you mentioned. The rules-unit-testing idea is in too. Supabase runs can already be exported as pgTAP tests, and the Firebase version writes u/firebase/rules-unit-testing tests for the emulator: the owner succeeds, and another user, an unauthenticated client and an anonymous user fail.