DEV Community

Cover image for Firebase Auth checks who. App Check checks what is calling your backend
Stacklyn Labs
Stacklyn Labs

Posted on

Firebase Auth checks who. App Check checks what is calling your backend

You wrote careful Firestore Security Rules. Every screen sits behind Firebase Authentication. The backend feels locked.

It isn't. Your google-services.json and GoogleService-Info.plist ship inside the APK and the IPA. Anyone with basic reverse-engineering tools can pull out your project ID and API keys, skip your Flutter UI completely, and fire requests at your backend with cURL or a short Python script.

Authentication answers who the user is. It says nothing about what is sending the request. Firebase App Check fills that gap.

The threat is the bill, not only the data

The expensive case is a Cloud Function that calls a paid third-party service: sending an SMS, generating an AI response. If that endpoint accepts any well-formed request, a script can call it thousands of times, and you pay for every call.

So the goal is to reject that traffic at the edge, before your code runs.

How attestation works

When your app starts, it asks a platform attestation provider to vouch for it:

  • Android: Play Integrity API
  • iOS: DeviceCheck or App Attest

The provider checks the device and the app's signature. If both look genuine, it issues a short-lived token. Your app attaches that token to every request to Firebase. Firebase checks it, and if the token is missing, invalid or expired, the request is dropped at the gateway. The script gets nothing and you are not billed for the compute.

Setup, and the one flag that matters

await FirebaseAppCheck.instance.activate(
  androidProvider: AndroidProvider.playIntegrity,
  appleProvider: AppleProvider.appAttest,
  isTokenAutoRefreshEnabled: true,
);
Enter fullscreen mode Exit fullscreen mode

Getting a token takes a network round trip to Apple or Google before your app talks to Firebase at all. If the token has expired when the user opens the app, the first data sync waits for that handshake. In an offline-first app, where the whole point is instant feedback, that delay is easy to notice.

isTokenAutoRefreshEnabled: true makes the SDK renew the token in the background before it expires. The token is already there when the user does something, and the handshake is no longer on the critical path.

Don't lock out real users on odd devices

Attestation is strict on purpose. A legitimate user on a rooted Android phone, a custom ROM or an iOS simulator will fail it. By default Firebase answers with Permission Denied, the user is stuck, and your crash dashboard fills with network errors that don't tell you why.

Listen to the token state and degrade instead of failing:

FirebaseAppCheck.instance.onTokenChanged.listen((String? token) {
  if (token == null) {
    // Attestation failed: rooted, emulated, or the provider refused.
    // Keep cached local data readable, switch off costly server calls,
    // and tell the user their device environment isn't supported.
    securityService.disableHighCostFeatures();
    ui.showUnsupportedDeviceNotice();
  } else {
    securityService.enableAllFeatures();
  }
});
Enter fullscreen mode Exit fullscreen mode

The pattern: reading cached local data keeps working, while expensive server operations (LLM calls, heavy queries) are switched off with a clear, polite message.

Enforce it everywhere, not just Firestore

App Check on your database alone leaves side doors open. Cover the whole project:

  1. Cloud Functions: reject requests without a valid X-Firebase-AppCheck header.
  2. Storage: enforce it on file reads so nobody scrapes your media and eats your bandwidth.
  3. Realtime Database: only genuine app builds open connections.
  4. Your own backend: read the header in your Express or Django middleware and verify the token with the Firebase Admin SDK before the route runs.

Your CI will break the day you turn it on

Integration tests on GitHub Actions or Bitbucket Pipelines run on virtual Linux runners. They can't pass Play Integrity, so every test request gets rejected.

Use the debug provider for those environments. Generate a debug token in the Firebase Console and store it as an encrypted CI secret:

- name: Run Flutter integration tests
  run: flutter test integration_test/app_test.dart
  env:
    APP_CHECK_DEBUG_TOKEN: ${{ secrets.FIREBASE_APP_CHECK_DEBUG_TOKEN }}
Enter fullscreen mode Exit fullscreen mode

Read that variable in your test configuration and enable the debug provider only in testing or staging builds. Production keeps real attestation.

Checklist

  • Activate App Check with Play Integrity and App Attest (or DeviceCheck).
  • Turn on isTokenAutoRefreshEnabled.
  • Handle a null token with a reduced mode, not a dead app.
  • Enforce on Functions, Storage, Realtime Database and any custom backend.
  • Give CI a debug token from a secret, never in production.

Further reading: Deep Dive: Protecting Firebase Backends with App Check.

Have you turned on App Check enforcement yet, or is something (CI, emulators, old devices) holding you back?

Top comments (0)