AIza…

Exposed Google API Key? Here's how to detect and rotate it

Found an AIza key in your code? Some Google keys are meant to be public. Learn which ones are fine, how to lock the rest down, and run a free Trust scan.

A Google API key (starting with AIza) authenticates calls to Google services like Maps, Cloud, and other APIs, and bills usage to your Google Cloud project. If the key is unrestricted, anyone who finds it can call those APIs on your project until you revoke or lock it down. Restricting a key to specific APIs and referrers limits the blast radius, but a leaked unrestricted key must be deleted or rotated.

What an attacker can do with a leaked Google API Key

How Google API Keys get exposed

Scan your repo and live site for exposed Google API Keys - free

Trust checks the files in your repo and the JavaScript your site ships. No signup, results in about a minute.

Run a free scan →

How to rotate a leaked Google API Key

  1. Go to console.cloud.google.com/apis/credentials and pick the affected project at the top.
  2. Find the leaked key under API Keys, open it, and click Delete - or click Regenerate/Rotate key to swap it.
  3. Note that deletion propagates gradually, so treat the old key as live for up to ~30 minutes.
  4. Create or edit the replacement key and add Application restrictions (HTTP referrers, IPs, or app) plus API restrictions so it only calls the services you need.
  5. Update your server environment or secrets with the new key and redeploy; never ship it in client code unrestricted.
  6. Open APIs & Services → Metrics (and Billing) to check for usage spikes or unexpected API calls from the abuse window.

Open the Google API Key dashboard →

Is every Google API key a problem?

No. Some Google keys are made to sit in your page code. A Maps JavaScript key or a Firebase web key is public by design. What protects these keys is not secrecy. It is the limits you set on them.

  • Usually fine: a browser key for Maps JavaScript or a Firebase web app, limited to your website address and only the APIs you use.
  • Worth fixing: a key with no limits, a key you use on a server, or a key that can call a paid API you did not mean to share.

Lock a key down in five steps

  • Open Google Cloud Console, then APIs & Services, then Credentials. Pick the right project first.
  • Open the key. Under Application restrictions, choose Websites and add your site addresses.
  • Under API restrictions, choose Restrict key and tick only the APIs your app calls.
  • Save, then wait a few minutes for the change to spread.
  • In Billing, add a budget alert so a surprise spike reaches your inbox early.

How Trust treats Google keys

Trust reads the JavaScript your live site ships. If it finds a Google key there, it marks it as needs review, not critical, because many of these keys are public browser keys. When the key sits next to Firebase or Maps settings, Trust treats it as the public browser key it is and stays quiet. If Trust does show you one, open it and check its restrictions. Trust's repo scan also looks for AIza keys in your files.

Other secret types to check

Keep your app safe