← All posts
firebasesecurityvibe-codingsecret-managementservice-account

Firebase Service Account Key Fix: Secure Your Vibe-Coded App

O

OverMCP Team

Quick answer

If you've leaked a Firebase service account key in a vibe-coded app, you need to immediately revoke the key in Google Cloud Console, rotate any related credentials, and remove the key from your codebase and git history. Then, enforce strict secret management (environment variables, secret manager) and add automated scanning to prevent future leaks. Acting fast minimizes the risk of account takeover and data breach.

What to check first

Before you panic, follow this checklist to assess the damage and contain the leak:

  • Identify the leaked key: Search your codebase, git history, and public repos for the service account key file (usually named serviceAccountKey.json or similar). Use grep or a secret scanner.
  • Check git history: Even if you removed the file, it may still exist in previous commits. Search with git log -S 'serviceAccountKey'.
  • Revoke the key immediately: Go to Google Cloud Console > IAM & Admin > Service Accounts, find the service account, and delete or disable the leaked key.
  • Rotate related credentials: If the key was used to access Firestore, Storage, or other services, rotate any associated tokens or passwords.
  • Audit access logs: Check Google Cloud audit logs for any unauthorized access using the leaked key.
  • Notify users if necessary: If the leak could expose user data, consider informing your users and regulators if required.
  • Step-by-step fix

    Follow these steps to fix the leaked Firebase service account key and harden your app.

    1. Revoke the leaked key

  • Go to Google Cloud Console.
  • Navigate to IAM & Admin > Service Accounts.
  • Select the service account associated with the leaked key.
  • In the Keys tab, find the key you suspect is leaked and click Delete or Disable.
  • Confirm the action. The key is now useless.
  • 2. Remove the key from your codebase and git history

  • Delete the key file from your project directory.
  • Remove it from git history using a tool like git filter-repo or BFG Repo-Cleaner. For example:
  • # Install git-filter-repo
    git filter-repo --path serviceAccountKey.json --invert-paths
  • Force-push the cleaned history to your remote repository. Warning: This rewrites history and may affect collaborators. Coordinate carefully.
  • 3. Use environment variables or a secret manager

    Never hardcode service account keys. Instead, store them in environment variables or a secret manager like Google Secret Manager.

  • Add the key to your environment:
  • export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/serviceAccountKey.json

    Or better, store the JSON content in an env var:

    // In your app
    const serviceAccount = JSON.parse(process.env.FIREBASE_SERVICE_ACCOUNT);
    admin.initializeApp({
      credential: admin.credential.cert(serviceAccount),
    });
  • For production, use a secret manager. Example with Google Secret Manager:
  • const { SecretManagerServiceClient } = require('@google-cloud/secret-manager');
    const client = new SecretManagerServiceClient();
    const [version] = await client.accessSecretVersion({
      name: 'projects/my-project/secrets/firebase-service-account/versions/latest',
    });
    const creds = JSON.parse(version.payload.data.toString());
    admin.initializeApp({ credential: admin.credential.cert(creds) });

    4. Add automated scanning

    Prevent future leaks by integrating a secret leak scanner into your CI/CD pipeline. OverMCP can scan your repositories and detect exposed keys before you deploy.

    5. Rotate keys periodically

    Even if you don't suspect a leak, rotate your service account keys every 90 days to reduce risk.

    Common mistakes

    Vibe-coded apps often make these mistakes that lead to leaked Firebase service account keys:

  • Hardcoding keys in client-side code: Service account keys should only be used server-side. Putting them in your frontend code exposes them to anyone.
  • Committing .env files: AI tools may automatically generate a .env file and commit it. Ensure .env is in .gitignore.
  • Ignoring git history: Removing a file doesn't remove it from history. Attackers can find it in old commits.
  • Using the wrong key type: Sometimes developers confuse a service account key with an API key. Service account keys grant full access, so leaks are critical.
  • Not using a secret manager: Storing keys in plain files or environment variables in code is risky. Use a managed secret service.
  • Why vibe-coded apps are especially at risk

    AI coding tools like Cursor, Bolt.new, and Replit Agent can generate boilerplate that includes placeholder credentials or accidentally include keys in code snippets. They may also scaffold projects without proper .gitignore rules, making it easy to commit secrets. Additionally, vibe coders often skip security best practices to ship fast, leaving keys exposed. Using a free AI app security scanner can catch these issues early.

    Long-term prevention

    Beyond immediate fixes, adopt these habits:

  • Use environment-specific configuration: Never share keys across environments.
  • Implement least privilege: Create service accounts with only the permissions needed.
  • Monitor for unusual activity: Set up alerts for API calls from your service account.
  • Educate your team (or yourself) on secret hygiene.
  • FAQ

    How do I know if my Firebase service account key is leaked?

    Search your codebase and git history for serviceAccountKey or .json files with private keys. You can also use a secret leak scanner to scan your repos automatically. Additionally, check Google Cloud audit logs for unexpected usage.

    Can I just delete the key and generate a new one?

    Yes, but also ensure you remove the key from your codebase and git history. Simply generating a new key doesn't stop an attacker who has the old one from using it until you revoke it. Always revoke the leaked key first.

    What should I do if the leaked key was used to access user data?

    Immediately rotate all related credentials, assess the breach scope, and notify affected users if their data may have been exposed. Consider informing regulatory bodies if required by law. Then, follow the steps above to prevent recurrence.

    ---

    Don't let a leaked Firebase service account key derail your launch. Use OverMCP's continuous security monitoring to keep your vibe-coded apps safe.

    Is your app secure?

    Free scan in 30 seconds. No signup needed.

    Scan My App Free