Common question

Is My Google Maps API Key Safe to Expose in My App?

Short answer: a Google Maps key in your website's code is normal, but it's only safe if you lock it down. If your app shows a Google map in the browser, the key goes to the browser too, so anyone can see it. Google's advice is not to hide a browser key but to restrict it. The danger is a key with no limits: someone can copy it, use it somewhere else, and the bill comes to you.

Check your live app for free

Paste your link. The free summary usually takes under a minute.

How to spot a Google key

Google API keys usually start with AIza. Open your live app, right-click and pick View page source, then search for AIza. A Maps key is often in a script tag like this one, the way Google's Maps JavaScript API docs show it (Google: Load the Maps JavaScript API):

<script async src="https://maps.googleapis.com/maps/api/js?key=AIza...&loading=async&callback=initMap"></script>

It can also be inside your app's own JavaScript files, so check those too if you can.

Why a public key can still cost you

Google is clear about who pays. Its Maps security guide says: "You are financially responsible for charges caused by abuse of unrestricted API keys." (Google Maps Platform security guidance)

A key with no limits can be used from any website. Google's Firebase docs add that a key with no API limits "can be used to access any API that is enabled for the project." (Firebase: API keys) So anyone who copies it can run up charges on your billing account.

The fix: two kinds of limits

Google's advice is to "always restrict your API keys with one type of application restrictions and one or more API restrictions." (Google Maps Platform security guidance)

In plain words, that's two locks:

  1. Where the key works (application restriction). For a website, pick Websites and list your own site with the full address, like https://yourapp.com. Google lets you use a wildcard such as https://*.yourapp.com to cover your subdomains.
  2. What the key can do (API restriction). Only tick the APIs your app really uses. If you show a map with the Maps JavaScript API, Google says to always tick that one. If your map also uses services like Geocoding or Places, tick the matching APIs too.

Google says that once you add these limits, only requests from the sites and APIs you picked are allowed. That makes a copied key much less useful to anyone else.

How to lock it down

  1. In the Google Cloud console, open the Google Maps Platform Credentials page. You can also find your keys under APIs & Services, then Credentials.
  2. Select your key.
  3. Under Key restrictions, choose Set an application restriction, pick Websites, and add your live web address (and your preview address if you use one).
  4. Under API restrictions, choose Restrict key, then open Select APIs and tick only the APIs your app uses.
  5. Select Save. Then open your live app and check the map still loads.
  6. Set a budget alert in the console's Billing section, under Budgets & alerts. Google says a budget alert sends you emails as spending grows, but it doesn't stop spending on its own.

If your key is already in use on a live app, Google says to check which APIs and sites are using it first, so the new limits don't block your own app.

If you're not sure which APIs your app uses, ask your AI builder. You can paste a prompt like this into Lovable, Bolt, Cursor or similar:

List every Google API my app calls (for example Maps JavaScript API, Places, Geocoding, Directions) and every place a Google API key (starting with AIza) appears in my code. Tell me which calls run in the browser and which run on the server. Don't change any code yet.

One key for the browser, another for the server

Some apps also call Google from server code, for example to turn an address into a map point. A key used only on the server should not be in your front-end code at all. Google says these server keys "are meant to remain a shared secret between the developer's servers and Google." Google suggests keeping them out of your source code, for example in environment variables, and limiting them to your server's IP addresses. (Google Maps Platform security guidance)

Google also says to use a separate key for each app. That way, if one key is leaked, you can delete or replace it without touching the others. If you call Google from both the browser and a server, Google recommends two separate projects, so you can set different usage limits for each.

If a server-only key has ended up in your public code, add limits to it first. If you still need a new key, Google's Rotate key button makes a new key with the same limits, and both work for a while. Put the new key in a server-side secret, update your app, then delete the old key. Google warns you to be careful when changing a key that's in use, so check your app straight after.

Is it the same as a Firebase key?

Firebase web apps also use a Google API key, but it works differently. Firebase says its keys are public by design, and what protects your data is your Security Rules and App Check. Firebase also says that if your app uses other APIs, like the Places API for Maps, you should use a separate key and restrict it to that API. (Firebase: API keys) So keep your Maps key separate from your Firebase key. See Is my Firebase API key safe to expose? and Are my Firebase Security Rules leaving my data open?.

What the rooGBotVC scan checks

Paste your URL in the box at the top of this page. The scan reads three places: the HTML tags on the page you scan (including the address in a Maps script tag like the example above, or a map iframe), the inline scripts on that page, and up to 15 script files served by your own site. It looks for text that matches the usual Google key pattern: AIza followed by 35 more letters, numbers, dashes or underscores.

  1. If it finds one, it shows "Google API key in public code" as a low issue. It shows the key with most of it hidden, says where it found it (an HTML tag, the inline scripts or a script file), and gives you fix steps for restricting it.
  2. If your app also ships a Firebase config, it shows a Firebase note ("check your Security Rules") instead of the Google key issue.

The scan has limits. It only checks the one page you scan. It doesn't run JavaScript, so a key added after the page loads won't be seen. It doesn't open script files hosted on other sites, such as Google's own Maps script; it only reads the address written in your page's tag. It can't see your Google Cloud settings, so it can't tell whether your key is already restricted. Treat a flag as a reminder to check, not as proof of a problem.

Related reading

  1. API keys exposed in your JavaScript: the bigger picture on keys in front-end code.
  2. How do I stop a surprise bill on my vibe-coded app?: spending limits for Supabase and Vercel.
  3. Are your source maps public?: another way code you didn't mean to share can leak.
  4. Lovable guide and Bolt guide: common things to check on apps from those builders.

The bottom line

A Google Maps key in your web page is expected. An unrestricted one is the problem, because you pay if someone else uses it. Lock it to your own website, limit it to the APIs you use, keep server keys off the front end, and set a budget alert. Paste your URL in the box at the top to see if a Google key shows up in your public code.

This is an automated, surface-level check of what your site shows the public. It is not a full security audit.