Use this when issuing, storing or revoking API keys.
API Keys
API keys are secrets that identify and authorize an application calling an API. Scope them narrowly, keep them out of code and repositories, rotate them and revoke them on any exposure.
1. API keys authenticate apps to APIs.
2. Scope minimal; restrict by IP/referrer.
3. Store in vaults/env injected at runtime.
4. Rotate and revoke.
5. Monitor usage.
key → API → scoped access
Context & applicabilityCommon mistakes · platform/version boundaries
- Keys committed to Git or included in mobile apps and front-end JavaScript.
- One key with full access used by many services.
- No IP or referrer restrictions where the provider supports them.
- No owner or expiry recorded.
Operational reference
Fast context before you go deeper.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- An API key acts as its owner to the API.
- Scope keys to the minimum permissions.
- Never commit keys to repositories.
gitleaks detect --source .— keys in code- Key scopes and IP restrictions — least privilege
- Key age — rotation
ReferenceWhy it matters1 section · depth on demand
Handling API keys
- Scope narrowly (specific APIs, read-only where possible) and restrict by IP or referrer where supported.
- Store in a secret manager or environment injected at runtime, not in code.
- Rotate regularly and immediately after exposure; support two active keys for zero-downtime rotation.
- Monitor usage for unusual volume or locations.
- Prefer short-lived tokens (OAuth, workload identity) over static keys.
ReferenceImportant terms & boundaries2 sections · depth on demand
In depth
API keys identify and authenticate applications calling an API. They are easy to use but are typically long-lived bearer credentials, so leaks are common and serious.
Good practice:
| Practice | Reason |
|---|---|
| Minimum scope | Read-only where possible |
| One key per consumer | Precise revocation and audit |
| IP/referrer restrictions | Limit where a leaked key works |
| Expiry and rotation | Bound the lifetime |
| Server-side only | Never embed in mobile apps or front-end code |
| Secret scanning | Detect commits containing keys |
Prefer short-lived tokens (OAuth client credentials, workload identity) over static API keys where the platform supports them.
Good practices
- One key per consumer and purpose, with least-privilege scopes.
- Store in a secret manager; inject at runtime.
- Restrict by IP, referrer or service where possible.
- Expire and rotate keys; prefer OAuth client credentials or workload identity over static keys.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Secrets Management → API Keys. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html · confidence 94%