An API key is a password for software. If someone else gets your payment, SMS or cloud key, they can spend your money or read your data. Most leaks are accidents, not clever attacks.
How keys leak
- Committed into a public code repository.
- Pasted into a chat group, email or document.
- Embedded in a mobile app or in website JavaScript, where anyone can read it.
- Left in screenshots or screen recordings.
- Shared with everyone because it is easier.
What to do instead
- Keep secrets in environment files or a secrets manager on the server, never in the code.
- Keep your repository private, and add the environment file to the ignore list.
- Use separate keys for testing and for live use.
- Give each key only the permissions it needs.
- Use a different key per person or service so that you can cancel one without breaking everything.
- Rotate keys regularly and immediately after a leak.
Mobile apps and websites
Anything inside the app or in front-end code can be extracted. Keep secrets on your server and let the app call your own API, which in turn calls the service. Public keys meant for the browser (such as a gateway's publishable key) are different from secret keys. Know which is which.
If a key leaks
- Revoke or regenerate it right away.
- Check the provider's usage logs for misuse.
- Update your server with the new key.
- Find out how it leaked and fix that.
Team habits
A quick audit
- Search your code for words like key, secret, token and password.
- Check your repository history, because deleted keys remain in older versions.
- Look at your hosting panel for old, unused keys.
- List who has access to each service and remove people who left.
Doing this once a quarter finds most problems early.
Remove access for people who leave, avoid sharing in chat and review who has what at least twice a year. A secure project is mostly small, boring habits applied consistently. Related reading: what an API is and the website security checklist.
