Insights / Security
API keys and secrets in business applications: rotation, scopes, and what to do when one leaks
API keys and secrets are the quietest way into a business application. Scopes, rotation, and a rehearsed leak response decide whether a leaked key is a footnote or a breach.
Kiran Bandarupalli · 9 Nov 2026 · 5 min read

Every business application runs on secrets it rarely talks about: API keys, database passwords, signing keys, webhook tokens. They leak in ordinary ways — a screenshot, a debug log pasted into a chat, a repository made public for five minutes. The difference between a leaked key that becomes a footnote and one that becomes a breach is decided long before the leak, by how the key was scoped, where it was stored, and whether anyone had practised revoking it.
Secrets management is not a security-team luxury. For a small business application it is some of the cheapest insurance available, because the controls are mostly process: fewer keys, smaller scopes, scheduled rotation, and a response plan written down before you need it.
A key is a credential — treat it like one
The first mistake is treating an API key as configuration. Configuration is safe to share, log, and commit; a credential is none of those. If a value would let a stranger read your data, send email as your business, or charge your account, it is a credential: keep it out of source control, logs, and screenshots, and make it revocable without redeploying the application.
A key baked into a Docker image or a build artifact can only be revoked by rebuilding and redeploying. Inject keys at runtime from the environment or a secret store, so rotating one means changing a value and restarting a process — the same discipline behind a deployment pipeline that proves what it ships.
Scopes: give every key the smallest job
Most services let you scope a key: read-only instead of read-write, one service instead of all of them, one environment instead of production and staging together. A key with the smallest scope that lets it do its job turns a leak from a catastrophe into a contained incident.
A reporting job needs read access to one database, not the application's full credentials. A third-party integration gets its own key per vendor, so revoking one vendor's access never means touching anyone else's. Short-lived, scoped credentials — the same idea behind signed download URLs with expiry — limit what a leaked value can do. Never share credentials between production, staging, and local development: a staging leak then becomes a production incident.
Where keys live — and where they must not
Environment variables managed by the hosting platform are a reasonable starting point for a small team. A dedicated secret manager is better once you have more than a handful of services, adding versioning, access logs, and rotation hooks. The rules matter more than the tool: who can read a secret, who can change one, and whether every read is logged.
The places keys must never live are depressingly familiar:
- Source control, including history: removing a key from the current commit does not remove it from the repository. Assume anything ever committed is compromised and rotate it.
- Client-side code and mobile apps — anything shipped to a browser or a device is public. Keys used there should be scoped to the point of uselessness, or replaced by a backend proxy.
- Logs and error reports — a failed request can put a live key into a log file or a support ticket. Scrub authorisation headers before they are written anywhere.
- Chat, email, and screenshots — the fastest way a key escapes is a well-meaning paste. If a key has been pasted into a chat, rotate it.
If keys are already scattered, audit them: search repository history for high-entropy strings, check the server hardening checklist for who can read the environment files, and list every place a key is read from. You will find two or three keys nobody can account for — rotate those first.
Rotation that actually happens
Rotation fails because it is manual, untested, and scheduled for "later". Make it boring: a short, repeatable procedure with two keys live at once during the changeover, so a straggler service does not break.
# A rotation that does not cause an outage:
# 1. Create key B alongside live key A. Do not delete A yet.
# 2. Update the secret store to B, restart one service, confirm it
# works. Then roll B out everywhere.
# 3. Watch logs for 24 hours. Any request still using A is a service
# you missed — find it before you revoke.
# 4. Revoke A. Confirm the old key now fails.
# 5. Record it: key name, date, who did it, what changed.Run it on a calendar, not on a scare. Ninety days is a sensible default for most API keys; database passwords and signing keys can go longer, but the interval matters less than the fact that the procedure has been rehearsed. Automate the reminder: a calendar entry and a named owner beat a policy document nobody reads.
When a key leaks: the first hour
Assume every leak is real until proven otherwise. Rotating a key that was never misused costs an hour; assuming a leak was harmless can cost far more. The first hour has a fixed order:
- Revoke or rotate the key first, investigate second. Containment before root cause. If you cannot revoke immediately, disable the key's permissions at the provider.
- Check what the key could reach. Its scope tells you the blast radius. Pull the provider's usage logs for the window between leak and revocation — you cannot investigate what you did not record, which is why observability for asynchronous work matters here too.
- Look for use that was not yours. New IP addresses, unusual volumes, calls at odd hours, exports or deletions — anything unfamiliar in that window is evidence, not noise.
- Rotate anything downstream. If the leaked key could read other secrets, rotate those too. Attackers follow the chain.
- Write it down while it is fresh. What leaked, where, when it was revoked, what the logs showed, and what changes afterwards.
Rehearse it before you need it
A leak response plan that has never been tested is a hope, not a plan. Once a year, pick a real key, walk through revoking it in staging, and time how long it takes to find every service that uses it. Each run surfaces the same three things: a service nobody remembered, a key with a wider scope than anyone thought, and a step that does not match reality.
The checklist
- One key per service, per environment — never shared across vendors or environments.
- Least-privilege scopes on every key.
- Secrets injected at runtime, never baked into builds or committed to source control.
- Authorisation headers scrubbed from logs and error reports.
- Rotation on a calendar with a named owner, using a two-key changeover.
- A written leak response: revoke first, check logs, rotate downstream secrets, record what happened.
- A yearly rehearsal in staging.
None of this needs new infrastructure. It needs a list of your keys, a decision about each one's scope, and a date on the calendar. The same exit thinking applies when you evaluate a vendor: check what leaving costs before you sign. If you want help auditing secrets, backups, and access across your own systems, talk to us — a short review usually finds the two or three keys nobody can account for.