Leaked a Firebase service account key? What to do now
First, make sure it's the right kind of key. Firebase has two that people mix up.
Home › Guides › Leaked a Firebase service account key? What to do now · Last updated · By Ember, SniffPup
Which key leaked?
- The web API key starts with
AIzaand sits in your Firebase config in browser code. It's meant to be public. Your security rules protect your data, not this key. See is my Firebase API key safe? - A service account key is a JSON file, often named something like
serviceAccountKey.jsonorfirebase-adminsdk-....json. Inside you'll see"type": "service_account"and a"private_key"field.
A service account key is used by the Firebase Admin SDK. Admin access skips your security rules, so whoever has the key may be able to read and change your database, storage and users. If one of these leaked, act now.
Revoke it
- Open the Google Cloud console for your Firebase project and go to IAM & Admin > Service accounts.
- Open the service account named in the JSON file's
client_emailfield. - On the Keys tab, find the key whose ID matches the file's
private_key_id, and delete it. - Create a new key only if your server still needs one, and store it as a secret on that server.
Deleting the key stops it working. Removing the file from a repo or site does not.
Check for misuse
- Look at Cloud Audit Logs for actions taken by that service account.
- Check Firestore, Realtime Database and Storage for data that was added, changed or deleted.
- Check Firebase Authentication for users you don't recognize.
- Look at your billing for unusual usage.
Clean up the source
Find where the file was exposed: a public repo, a deployed folder, a front-end bundle or a shared chat. Remove it there too, and check other copies of the project. Our exposed .env or .git files guide covers files left on a live site.
Keep it from happening again
- Never put a service account key in browser or mobile app code. Admin access belongs only on a server.
- Add key files to
.gitignore. - Where you can, use your hosting platform's built-in credentials instead of a key file.
- Give each service account only the roles it needs.
For keys from other providers, see the leaked API key guide. To check your live site for exposed files, run a free scan at sniffpup.com.
FAQ
Is the Firebase web API key the same as a service account key?
No. The web API key starts with AIza and sits in your Firebase config in browser code. It's meant to be public. Your security rules protect your data, not this key. A service account key is a JSON file, often named something like serviceAccountKey.json, with "type": "service_account" and a "private_key" field. Admin access skips your security rules.
Does deleting the file revoke a leaked service account key?
Deleting the key stops it working. Removing the file from a repo or site does not.
Where do I revoke a leaked Firebase service account key?
Open the Google Cloud console for your Firebase project and go to IAM & Admin > Service accounts. Open the service account named in the JSON file's client_email field. On the Keys tab, find the key whose ID matches the file's private_key_id, and delete it.