How an Unrestricted API Key in HTML Source Can Cost a Company $20,000 a Week
Two Google Maps API keys were hardcoded in public HTML and JavaScript bundles without any restrictions, allowing anyone to use them and bill the company's Google Cloud project. The author demonstrated that the keys worked from any origin and could be used to make many requests without throttling, potentially incurring large costs.
Published on prateekpulastya.medium.com
I found two Google Maps Platform API keys hardcoded into the public HTML and JavaScript bundles of a production web property. Both keys had no HTTP referrer restrictions, no IP restrictions, and no API service restrictions.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the developers hardcoded the API keys in client-side code without applying HTTP referrer or API restrictions in Google Cloud Console.
Impact
An attacker could use the unrestricted keys to make many API requests, potentially incurring significant costs billed to the company, with the only limit being Google's per-key quota.
What the attacker needed
Publicly accessible website; API key embedded in client-side code; No restrictions on the API key
The fix
The keys should be restricted with HTTP referrer and API restrictions in Google Cloud Console.
How it was found
- Fetch the target's homepage and search for a Google API key pattern.
- Fetch a JavaScript bundle and search for another Google API key pattern.
- Use the extracted key to call a Google Maps API endpoint without a Referer header.
- Observe that the API returns a successful response, indicating the key is unrestricted.
- Test additional APIs to confirm the lack of restrictions.
- Run a small load test to show sustained usage without throttling.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
An API key is like a password that lets software use a paid service, such as Google Maps. If that key is left in a website's public code and not locked down, anyone can copy it and use the service on the owner's bill. Here, the keys had no restrictions, so an attacker could run up charges.
What is Leaked secrets?
Keys, tokens or passwords left in public code, apps, logs or responses, that grant real access.