How to fix: Google Maps API key in source
Google Maps API keys (AIzaSy*) in client code can be abused to bill against your account.
Why it matters
An unrestricted Google Maps API key found in client code lets anyone generate maps requests billed to your account, potentially resulting in thousands of dollars in unexpected charges before the key is noticed and revoked.
Google Maps API keys (AIzaSy*) in client code can be abused to bill against your account.
How to fix it
- 1Restrict the key by HTTP referrer to your domain(s) in Google Cloud Console
- 2Set an API quota limit to cap maximum daily spend
- 3Rotate the key if it has been exposed without referrer restrictions
Code examples
Google Cloud: restrict API key by referrer (gcloud CLI)
# Restrict the Maps API key to your domains only
gcloud services api-keys update YOUR_KEY_ID \
--api-target=service=maps-backend.googleapis.com \
--browser-key-allowed-referrers='https://yourdomain.com/*,https://www.yourdomain.com/*'Server-side proxy for Maps (recommended for high-traffic)
// Proxy Maps requests through your API so the key never reaches the browser
export async function GET(req: Request) {
const url = new URL(req.url);
const address = url.searchParams.get('address');
const res = await fetch(
`https://maps.googleapis.com/maps/api/geocode/json?address=${encodeURIComponent(address!)}&key=${process.env.GOOGLE_MAPS_API_KEY}`
);
return Response.json(await res.json());
}References
Detected automatically by VulnRadar. The check id is secret-google-maps-api-key, stable across every scan so you can filter or diff on it.
More secrets checks
Questions
- How severe is Google Maps API key in source?
- VulnRadar rates this medium severity in the secrets category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id secret-google-maps-api-key, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does Google Maps API key in source map to?
- It maps to CWE-798. In the OWASP Top 10 it falls under A07:2021.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.