TL;DR
- A key is a string that proves a program may call a service, and nothing more.
- A key works for whoever holds it, so a copied key is a working key.
- Keys reach public code and logs more often than teams expect, and bots search for them.
- The fix is to rotate, move and narrow keys, or to replace them with short-lived identity.
Before you start: an API key is a simpler cousin of the access token. Read that one first if the word “token” is new to you.
What an API key is#
An API is the door a program uses to ask a service for something: send a message, read a file, start a job. An API key is a long random string the service gives you so it can tell your program apart from everyone else’s.
You put the key in a script, an app or an environment variable. The service checks it on every call. If the string matches an active key, the call goes through. That is the whole check.
A wristband at a festival#
Think of a festival wristband. Whoever wears it gets in. The gate staff do not look at your face or your ticket. If someone photographs your wristband and posts the photo, the photo gets in too.
An API key behaves the same way. The service checks the string, not the person holding it. The standard for bearer tokens says the same about tokens in general: anyone who holds one can use it, without proving they are the one it was issued to. Most API keys are used this way, so treat every copy as the real thing.
How keys leak#
Keys end up in places they should not be: a config file pushed to a public repository, a screenshot in a bug report, a chat message, a build log. Nobody meant to publish them. The file was just convenient.
Microsoft Threat Intelligence reported on 5 November 2026 that threat actors were using an agentic AI tool to search public GitHub repositories for exposed secrets, including AI inference API keys. In at least one case, Microsoft says an agent went from scanning GitHub to pulling data from Azure Key Vault in five minutes. No break-in was needed. The keys were already public.
The sequence below shows that path in four steps. The one that matters is the call that still works with the copied key.
What to do instead#
Start with the key you already have. If it was ever in a repository, a log or a chat, treat it as leaked. Revoke it and issue a new one, then check what the old one touched. Revoking is the step that stops the copy from working.
Next, move the key out of the code. A secret store or the platform’s built-in vault keeps the string out of the repository, and push protection can block a key before it is committed. Turn on secret scanning for every repository that holds configuration.
Then narrow it. One key should serve one service, with the fewest permissions that work, and it should be rotated on a schedule. A key that can do everything is the one a scanner wants.
Where the platform allows it, skip the key altogether. A workload can prove who it is with a short-lived token instead of a string it keeps. The secrets or federation article shows how a CI job does this with no stored secret.
Key or token?#
A key says which program is calling. A user token says which person signed in, and what that person agreed to. A key usually carries no user at all, and many keys never expire unless someone rotates them. That is why a leaked key can be worse than a stolen sign-in: nobody sees a login prompt, and no timeout runs out on its own.
Where to go next#
- Secrets or federation: how a CI job proves who it is with no stored password.
- Access, refresh and ID tokens: the three tokens you will meet next, and what each one is for.
- OAuth 2.0 flows explained: how a user-facing app gets a token in the first place.
- Infostealers now take AI agent tokens: what to revoke when a token or key is stolen from a laptop.
Sources#
This post as Markdown · RSS · JSON feed
New posts by email
One email a week with new posts and labs. Unsubscribe anytime.
Your address is stored with Kit, which sends the emails. Details