How I Dealt with an Exposed API Key on GitHub
The author accidentally committed a real Gemini API key into a tracked .env.example file in a public GitHub repository. Automated systems found the key and made 145 unauthorised API calls before the author noticed and revoked it.
medium.com
Published on medium.com
Because of this, hackers or automated crawling systems were able to find and use my API key. As a result, 145 API calls were made without my permission.
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 AI assistant wrote a real API key into a .env.example file that was not listed in .gitignore, so the secret was committed and pushed to a public repository.
Impact
An unknown party or automated system used the exposed key to make 145 API calls on an expensive model, incurring a small cost to the author.
What the attacker needed
Public GitHub repository; real API key committed to a tracked file; automated secret scanning by third parties
The fix
The author fixed .gitignore, removed the commit history containing the key, and revoked and replaced the exposed API keys; the text does not say the repository was otherwise remediated.
How it was found
- The AI generated a .env.example file and the author copied its contents into a real .env file.
- The author pasted the API key into the terminal when running the script, and the AI inserted that key into .env.example.
- The author reviewed only the code, not the configuration files, and pushed the commit to the public GitHub repository.
- Automated systems found the exposed key and made 145 API calls using an expensive model.
- The author noticed the calls in the Google AI Studio usage dashboard.
- The author fixed .gitignore, removed the commit history containing the key, and revoked and replaced the exposed keys.
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 a program use a paid service. The author put a real key into a file that was uploaded to a public code-sharing site, so anyone (or any bot) could copy it and spend the author's money. The lesson is to keep secrets out of code that gets shared.
What is Leaked secrets?
Keys, tokens or passwords left in public code, apps, logs or responses, that grant real access.