Leaked API key risks
Someone with a leaked API key can do anything the key allows, from anywhere, until it is revoked. An API key is a bearer credential: the service checks that the key is valid, not who is holding it. What that means depends on the key:
- A cloud provider key can start machines, read storage, change permissions and run up a bill.
- A payment, email or messaging key can send money, mail or texts in your name.
- A database or SaaS key can read and export customer data.
- An AI provider key can run requests charged to your account.
- A key held by an AI agent or integration can do everything that tool can do, which is often more than anyone remembers granting.
And a leak is rarely noticed at once. GitGuardian’s 2025 report found that 70% of the secrets it saw leaked in 2022 were still valid when it checked, years later.
First-hour API key leak response
Respond to a key leak in this order. Speed on the first step matters more than tidiness on the rest.
- Revoke or replace the key. If the service lets you revoke at once, do it. If you need the integration to keep working, create a replacement, deploy it, confirm the new key works, then delete the old one. OWASP’s remediation guidance puts revocation first: exposed keys should undergo immediate revocation.
- Check what it was used for. Look at the provider’s access and usage logs from the moment of exposure onward. Look for unfamiliar IP addresses, new resources, permission changes, exports and spikes in usage.
- Contain anything it touched. If the key could create users, keys or machines, look for new ones and remove them. If it could read data, treat that data as exposed and follow your incident and notification process.
- Remove the secret from where it leaked. Delete it from the file, chat or ticket, and rewrite repository history if needed. Do this after revocation, because copies may already exist.
- Find the cause. Work out whether it was committed by mistake, printed in a log, pasted into an AI tool, or shipped in an app. Fix the habit, not only the instance.
If the key was in a public GitHub repository, GitHub’s secret scanning runs automatically on public repositories and notifies participating providers so they can act, such as revoking the credential. Treat that as a safety net, not a plan.
Key scoping and short-lived credentials
The next leak matters less when every key is smaller, shorter-lived and rarer.
- Scope each key to one job. A key that can only read one resource is a small incident. A key with full access to everything is a breach.
- Prefer short-lived credentials. AWS recommends temporary credentials over long-term access keys wherever possible, and IAM roles for workloads so no long-lived key is distributed at all. OWASP describes dynamic secrets that are generated per session and expire on their own.
- Keep keys in a secret manager. Not in code, config files, chat or tickets.
- Remove keys nobody uses. AWS’s guidance is to review last-used information and delete unused credentials regularly.
- Never ship a broad key in a client. A key inside a browser bundle or a mobile app can be read by anyone with the app.
Fewer long-lived shared secrets
A secret that does not exist cannot leak. Every long-lived key is a standing way in, copied into every place it is configured. A device-issued identity replaces the shared secret with a key pair whose private half never leaves the device: the device proves who it is with a signature over a fresh challenge, so there is nothing to paste into a repository and nothing to replay.
Offline Protocol is designed around that idea. Devices identify each other with Ed25519 keys they generate and hold themselves, sessions are end-to-end encrypted with MLS, and a local mesh needs no portal account and no API key, so the device-to-device side of an application carries no shared secret at all. An app API key is needed only for hosted services: hosted MCP, SDK telemetry and CLI use in CI. Each of those keys belongs to one application and can be limited to one product and one access level, and the portal stores only a hash of each one, so a lost key is replaced, never recovered. Deleting a key revokes hosted access without touching device identity or local records, so a leak in the cloud never takes a site’s local coordination down with it.