Guides · Updated 2026-11-15
Private key (BEGIN PRIVATE KEY) or Firebase service-account JSON in my frontend: what to do
Short answer: It's one of the worst things a site can ship. A service-account JSON contains a private key that lets anyone sign in as that service account, with no password or 2-step check. If it's the Firebase Admin SDK account, Google's docs say server libraries using it bypass Firestore Security Rules, and the Admin SDK gets full read and write access to Realtime Database. Treat it as leaked: disable the key in Google Cloud (IAM > Service accounts > Keys), check what it did, delete it, and move every piece of code that needs it to a server route.
What you're looking at
A line like -----BEGIN PRIVATE KEY----- marks the private half of a key pair. In vibe-coded apps it usually comes from a Google Cloud or Firebase service-account key file: a JSON with fields like "type": "service_account", "project_id", "client_email" (ending in .iam.gserviceaccount.com) and "private_key". Google's docs describe this file as the private portion of the key pair, available only to you.
- Firebase web config (apiKey, authDomain, projectId...) is NOT this. Firebase says those API keys don't need to be treated as secrets; your Security Rules protect the data. Read more: https://leakyvibe.com/guides/is-my-firebase-database-open-firestore-rules-test-mode
- A service-account JSON IS a secret. Whoever has it can authenticate as that account and do anything its roles allow.
- Other PEM private keys (RSA, EC, OPENSSH) used for signing tokens, payments or SSH are just as sensitive. The steps below are the same idea: revoke at the source, then move the code to a server.
Why it's so serious
Google's best-practices page puts it plainly: a leaked service-account key lets a bad actor authenticate and gain a foothold in your environment, and it can be worth more to them than a leaked password, because service accounts don't get 2-step verification or login challenges.
For Firebase apps it's worse. The key the console gives you under Project settings > Service accounts > Generate new private key is for the Admin SDK. Firebase's docs say the server client libraries bypass all Cloud Firestore Security Rules, and that the Admin SDK authenticated as an Editor service account has complete read and write access to Realtime Database. So your carefully written rules don't apply to whoever holds that file.
How it ends up in the browser
A common thing we see: someone asks the AI tool to "send a notification", "read all users" or "call a Google API" from the app. The fastest working code imports the service-account JSON into a page component, or puts it in an env var like VITE_FIREBASE_SERVICE_ACCOUNT or NEXT_PUBLIC_GOOGLE_PRIVATE_KEY. Anything imported by client code, and any VITE_ or NEXT_PUBLIC_ variable, is copied into the JavaScript every visitor downloads. More on that: https://leakyvibe.com/guides/is-my-vercel-app-leaking-environment-variables
5-minute check: does my live site ship a private key?
- Open your live site in a private window.
- Open DevTools (F12), go to Sources (Debugger in Firefox) and use "Search in all files" (Ctrl+Shift+F, or Cmd+Option+F on Mac).
- Search for BEGIN PRIVATE KEY, then service_account, then private_key and gserviceaccount.com.
- Also search your repo and its git history (git log -p | grep -n "PRIVATE KEY") in case the file was ever committed, especially if the repo was public.
Or paste your URL in the free scan at the top of this page. It reads the HTML and JavaScript your site serves and flags PEM private keys (BEGIN PRIVATE KEY, RSA, EC, OPENSSH and others) as a critical finding.
Found one? Do this, in this order
- Find the account: the client_email in the JSON tells you which service account it is, and private_key_id tells you which key.
- In Google Cloud console, go to IAM & Admin > Service accounts, open that account, then the Keys tab. Disable that key now. Google recommends disabling first and deleting once you're sure nothing needs it, because a deleted key can't be undeleted.
- If your server still needs access, create a new key (or better, use the platform's built-in identity) and store it only in server-side environment variables.
- Check what the account did: in Cloud Logging, look at audit logs for that service account's email, and check Firestore, Realtime Database, Storage and Firebase Authentication for changes you didn't make. Check Billing for unexpected services.
- Delete the leaked key. Note from Google's docs: deleting a key doesn't revoke short-lived tokens already issued with it. If you see suspicious activity, disable the service account itself for a while (anything using it loses access immediately).
- Remove the key from your code and git history, and redeploy. Then reduce the account's roles to only what the server code needs.
Full checklist for any leaked secret: https://leakyvibe.com/guides/leaked-api-key-what-to-do
The safe fix: the key lives only on the server
- Move admin work (send notifications, read all users, write data on someone's behalf) into a server route or a Cloud Function. The browser calls that route; it never sees the key.
- In that route, check who is calling: verify the user's Firebase ID token and confirm they're allowed to do that action, before using admin privileges.
- For normal reads and writes, use the client SDK with Security Rules instead of the Admin SDK. That's what the rules are for.
- On Google Cloud (Cloud Run, Cloud Functions, Firebase Functions), you often don't need a key file at all: the code runs as an attached service account. Outside Google Cloud, Google suggests Workload Identity Federation instead of long-lived keys.
- Never name a server secret with VITE_ or NEXT_PUBLIC_.
A prompt you can give your AI tool
A Google/Firebase service-account key (private key / service account JSON) is in my frontend. Find every place it is imported, read from an env var, or used by client code (including VITE_* or NEXT_PUBLIC_* variables and any firebase-admin import in client components). Move all code that needs admin access to server routes (or Cloud Functions) that verify the user's Firebase ID token and check permissions first. Use the client SDK with Security Rules for normal user reads and writes. Load the key only from a server-only env var. Delete the JSON file from the client and from the repo. Don't print any key values. List the files you changed.
Sources
Official sources (checked 2026-11-15): Google Cloud IAM, "Create and delete service account keys" (https://cloud.google.com/iam/docs/keys-create-delete): key file format with -----BEGIN PRIVATE KEY-----, private portion available only to you, disable before deleting, deleted keys can't be undeleted, deleting doesn't revoke issued short-lived credentials. Google Cloud IAM, "Best practices for managing service account keys" (https://cloud.google.com/iam/docs/best-practices-for-managing-service-account-keys): leaked keys give attackers a foothold and skip 2-step verification; don't commit or embed keys. Firebase, "Add the Firebase Admin SDK to your server" (https://firebase.google.com/docs/admin/setup): Generate New Private Key, privileged environments only. Firebase, "Introduction to the Admin Database SDK" (https://firebase.google.com/docs/database/admin/start): admin privileges = complete read and write access, regardless of Security Rules. Firebase, "Get started with Cloud Firestore Security Rules" (https://firebase.google.com/docs/firestore/security/get-started): server client libraries bypass all Security Rules. Firebase, "API keys for Firebase" (https://firebase.google.com/docs/projects/api-keys): Firebase API keys don't need to be treated as secrets.