API Key
An API key is a long secret code that identifies an application or account when it calls an API. Anyone who has the key can usually use it, so leaked keys are a common cause of data breaches and surprise bills.
Also called: API keys, API token, access key, secret key
What is an API key?
An API key is like a password for software. When your website calls a payment, mapping, email or AI service, it includes the key so the provider knows which account to use and bill. OWASP notes that API keys identify the calling application but aren't a strong way to identify users, and should be protected and restricted like any secret.
How API keys leak
MITRE ATT&CK documents attackers hunting for credentials left in files and code. Common leaks:
- Keys committed to code repositories, especially public ones on GitHub.
- Keys embedded in websites or mobile apps, where anyone can extract them.
- Keys shared in chat, email, tickets or documentation.
- Keys left on old servers or in backups.
Leaked cloud and AI service keys are quickly abused, for example to run cryptomining, send spam or access data, leaving the business with the bill.
Best practices
- Never put secret keys in front-end code, mobile apps or code repositories. Store them in a secrets manager or environment settings.
- Restrict each key: limit it to specific services, IP addresses, domains or actions.
- Give each app or integration its own key, so one can be revoked without breaking others.
- Rotate keys regularly and immediately when someone leaves or a leak is suspected.
- Turn on secret scanning in your code repositories, and set billing alerts with API providers.
Related terms
Sources
- REST Security Cheat Sheet (OWASP)
- Unsecured Credentials: Credentials In Files (T1552.001) (MITRE ATT&CK)
Drafted with AI assistance, then edited and fact-checked by a person. How we use AI.
