AppInspected

Fix guides

There's a private key in your website's code. Shut it off, then find out what it was used for.

Last reviewed November 10, 2026 against the providers' current documentation.

The short version

Find out what the key belongs to: if the same JSON has "type": "service_account", a client_email and a private_key_id, it's a Google Cloud or Firebase service account key, and anyone who copies it can act as that service account. In the Google Cloud console, open IAM & Admin → Service accounts, click the account from client_email, open Keys and delete the key whose ID matches private_key_id. Then check Logs Explorer for what the key did, and move the code that needed it to a server. Google's own advice: client-side apps shouldn't use service accounts at all.

Why it matters

A private key is the half of a key pair that proves who you are, so whoever has it can sign in as its owner. Google's best practices say a leaked service account key gives an attacker the resources that service account was granted, and that signing in with a leaked key is likely to succeed because service accounts skip the extra sign-in checks a person gets. The default Firebase Admin SDK key is a strong one: Firebase describes the Admin SDK as working "with full admin privileges" from privileged environments, and Firestore's server client libraries bypass all Security Rules. So a page that ships that key gives any visitor full read and write access to your database, however good your rules are. A key stays valid until someone disables or deletes it.

Fix it, in this order

  1. Work out what the key is

    Search your code and build settings for BEGIN PRIVATE KEY. A Google service account key comes as a JSON file with "type": "service_account", project_id, private_key_id, private_key and client_email (an address ending in .iam.gserviceaccount.com); Firebase's Generate New Private Key button (Project settings → Service accounts) makes exactly this file. Variables such as VITE_FIREBASE_PRIVATE_KEY or NEXT_PUBLIC_GOOGLE_PRIVATE_KEY are the usual way in. If it's some other key (a JWT signing key, an Apple or payment provider key, a TLS or SSH key), replace it wherever it was issued and treat everything it signed as untrusted; the steps below are for Google keys.
  2. Delete the key

    In the Google Cloud console, open IAM & Admin → Service accounts, select the project, click the service account's email, open the Keys tab and click Delete next to the key whose ID matches private_key_id. Google's docs say a deleted key can't be undeleted, so if a server of yours also uses this key, create a new key for the server first. If you'd rather switch it off while you check, gcloud iam service-accounts keys disable KEY_ID --iam-account=SA_EMAIL --project=PROJECT_ID disables it (the console can't disable keys, only delete them), and you delete it once the new setup works.
  3. Stop tokens already issued

    Deleting or disabling a key doesn't revoke the short-lived access tokens already created with it; Google says those can stay valid for up to an hour (longer if your organization extended token lifetimes). If you think the key was used, disable the service account itself (or add an IAM deny policy for it), wait at least 60 minutes, then turn it back on. Anything that uses that account stops working during the wait.
  4. Check what the key did

    Open Logging → Logs Explorer and search for calls made with the key: protoPayload.authenticationInfo.serviceAccountKeyName:"KEY_ID", or for everything the service account did: protoPayload.authenticationInfo.principalEmail="SA_EMAIL". Admin Activity logs are always written, so look for new service accounts, new keys, IAM changes, VMs and buckets you didn't create. Data reads, such as someone downloading your Firestore documents, only show up if Data Access audit logs were turned on before, which is off by default, so assume the data the account could read has been read.
  5. Move the code to a server

    Whatever the page did with the key, do it on a server: an API route, a Cloud Function, a Supabase Edge Function or a Cloudflare Worker that requires a signed-in user, checks what that user may do, and returns only what the page needs. Store the key there as a secret (or, on Google Cloud, use the runtime's attached service account and skip keys entirely). For Firebase data the browser should read directly, use the normal Firebase web SDK with Security Rules: the web config (apiKey, projectId) is meant to be public, the Admin SDK key isn't.
  6. Clean up and stay notified

    Remove the key from source, .env files and build settings, rebuild and deploy. Old JavaScript stays in browser caches, CDNs and web archives, which is why deleting the key comes first. Make sure your project has current owners and security contacts: Google says it emails them when it finds a leaked key, and since June 16, 2024 it disables keys it finds exposed (the iam.serviceAccountKeyExposureResponse policy). Google describes that detection as working with public repositories such as GitHub and GitLab, so don't count on it for a key in your website.

Or ask your AI tool to do it

Paste this into Lovable, Bolt, Cursor, Claude Code or whichever tool built your app. Review what it changes before you deploy.

My website's frontend contains a private key (-----BEGIN PRIVATE KEY-----), most likely a Google Cloud or Firebase service account key. List every place in the code, env files and build settings that holds a service account key, private_key, client_email or GOOGLE_APPLICATION_CREDENTIALS value, and every call that uses it (Firebase Admin SDK, firebase-admin, googleapis, Google Sheets, Drive, Firestore, Cloud Storage and so on), with what each call does. Remove every private key and service account value from client-side code and from any VITE_, NEXT_PUBLIC_, REACT_APP_ or EXPO_PUBLIC_ variable. Move each call into a server-side endpoint that reads the key from a server-only secret (or uses the platform's built-in service account), requires a signed-in user, checks that the user may do that action, validates the input and returns only what the page needs. Where the page only reads or writes the signed-in user's own Firestore data, use the Firebase web SDK with Security Rules instead of the Admin SDK. Tell me which IAM roles the new service account needs for these calls, and nothing more. Finally, remind me to delete the old key in Google Cloud (IAM & Admin > Service accounts > Keys) and to check Logs Explorer for calls made with it.

How this happens

Usually a shortcut to data the browser isn't allowed to touch. "Use a Google Sheet as the database", "send push notifications", "let the admin page edit any user" or "my Firestore rules block this write" all work instantly once the Firebase Admin SDK or the Google APIs client gets a service account key, and an AI coding tool asked to fix a permission error will often paste the downloaded JSON into the project and read it through a VITE_ or NEXT_PUBLIC_ variable, which copies it into the public bundle. The escaped \n line breaks in private_key are a common sign the value came from that JSON file.

Check that the key is gone

After you deploy the fix, run the free check again: it reads your live page and JavaScript the way a visitor would and flags private keys and other secret keys it can see.

Topic check: Exposed API key checker

Find the other leaks before someone else does

The free check reads your home page and its scripts. The website security report goes through up to 30 pages and 40 JavaScript files, plus .env and .git files, security headers, cookies and CORS, domain and email records, and libraries with known vulnerabilities. Every finding comes with the fix for your host and a prompt for your AI tool.

$19 once, including 20 runs over 30 days so you can fix things and check again.

Get the report, $19 See an example report

Example report header: a score out of 100, findings by severity, Download PDF and Email me this report.

Questions

Is it really a problem if my site has nothing valuable?

Yes, because the key isn't limited to your site. It works against everything the service account can reach in your Google Cloud or Firebase project: the database, storage, users, and often the ability to create resources that end up on your bill.

My Firestore Security Rules are strict. Doesn't that protect me?

Not against this key. Firebase's docs say the server client libraries bypass all Cloud Firestore Security Rules and are controlled by IAM instead, and that the Admin SDK works with full admin privileges. Rules only protect you from the web SDK and its public config.

Will Google disable the key for me?

Maybe, but don't wait. Since June 16, 2024 Google disables service account keys it detects as exposed, unless the organization chose WAIT_FOR_ABUSE, and it emails project owners and security contacts. Google describes the detection as working with secret scanning on public repositories such as GitHub and GitLab; it doesn't say it scans websites.

A key Google disabled for exposure broke my server. Can I turn it back on?

Google's best practices say exposed keys it disabled can be re-enabled if you need to end an outage, and should be disabled again as soon as possible. Better: create a new key (or move to keyless authentication) for the server and delete the exposed one.

Is the Firebase web config in my page a private key too?

No. The apiKey, authDomain and projectId in the web config are meant to be public; the free check marks them as fine. The service account JSON with private_key is the secret one.

Does your check use the key?

No. The free check is passive: it finds the start of a PEM private key in your page and its JavaScript, shows it cut short, and never uses it. Only your Google Cloud console and logs can tell you whether the key is active and what it did.

Sources

Related guides