Skip to content

What to do in the first 10 minutes after you leak an API key

A minute-by-minute playbook for a leaked API key: identify it, kill it, ship a replacement, check for abuse, clean up. Steps for OpenAI, Stripe and AWS.

Keysquid team6 min read
On this page
  1. Minute 0–1: Assume it is already compromised
  2. Minute 1–3: Identify exactly which key it is
  3. Minute 3–5: Kill the key
  4. Minute 5–7: Ship the replacement
  5. Minute 7–9: Look for abuse
  6. Minute 9–10: Contain the source
  7. After the first 10 minutes
  8. How Keysquid fits in
  9. FAQ

You pushed a commit and noticed, a second too late, that .env went with it. Or a key showed up in a screenshot, a support ticket, a public gist or a CI log. What you do in the next ten minutes decides whether this is a non-event or a bill, a breach and a long week.

The single most important fact: once a secret has been exposed, deleting it from where it leaked doesn't un-leak it. GitHub's own documentation says that if you commit a secret you need to revoke or rotate it, and that commits can remain reachable through clones, forks, cached views and pull requests even after you rewrite history (GitHub Docs). Cleanup comes last. Killing the key comes first.

Here is the playbook, minute by minute.

Minute 0–1: Assume it is already compromised

Don't spend the first minute on git revert or on hoping nobody noticed. Public sources are watched continuously by automated scanners, which is why GitHub runs a secret scanning partner program that sends matches in public repositories straight to the providers that issued them (GitHub Docs). GitHub's advice is to treat any flagged secret as public and compromised. Do the same.

Write down three things in a scratch note or incident channel, with a timestamp: what leaked, where it leaked, and when it was first exposed. You'll need the timeline for the abuse check in minute 7.

Minute 1–3: Identify exactly which key it is

You can't revoke what you can't find. Most keys announce their issuer in their prefix:

PrefixIssuer and type
sk-proj-, sk-svcacct-, sk-admin-OpenAI project, service account or admin key
sk-ant-api…, sk-ant-admin…Anthropic API or admin key
sk_live_, rk_live_Stripe live secret or restricted key
AKIA…AWS long-term access key ID (the secret key travels with it)
ghp_, github_pat_GitHub personal access token
xoxb-, xoxp-Slack bot or user token

Then answer: which account, project or environment does it belong to, and what can it do? An admin key or an unrestricted Stripe secret key is a five-alarm fire; a read-only, spend-capped key is a two-alarm one. If several values leaked at once (a whole .env file), list them all and work down from the most powerful.

Minute 3–5: Kill the key

This is the step that actually ends the exposure. For a leaked key, revoke first and accept a short outage. A planned overlap rotation, where the old key keeps working while you roll out the new one, is right for routine rotations (our OpenAI rotation guide shows one), but not for a key someone else may already be using.

How to kill it quickly, per provider:

  • OpenAI: delete the key in the project's API keys page, or with the Admin API: DELETE /v1/organization/projects/{project_id}/api_keys/{key_id} (API reference).
  • Stripe: on the API keys page, choose Rotate key and set the expiration to Now, which deletes the old key and gives you a replacement immediately. Stripe lists a compromised key as a reason to rotate, to block potentially malicious requests (Stripe Docs).
  • AWS: deactivate the access key right away (aws iam update-access-key --access-key-id AKIA… --status Inactive --user-name …), then delete it once you have what you need for the investigation (AWS IAM docs). AWS may already have quarantined it: it applies targeted policies to exposed keys and notifies you through the AWS Health Dashboard, email and a support case (AWS re:Post).
  • Anything else: find "revoke", "delete", "regenerate" or "roll" in the provider's key settings. If the provider can't revoke a single key, rotate the account credential or contact their support.

If a provider offers both "disable" and "delete", disable first when you want the key's metadata for the investigation, and delete when you're done.

Minute 5–7: Ship the replacement

Now restore service. Create a new key, with narrower permissions than the old one if the provider allows it: a Stripe restricted key instead of a full secret key, an OpenAI service account key scoped to one project, an AWS role instead of a long-term access key where you can.

Put the new value everywhere the old one lived: hosting platform, CI secrets, secret stores, workers. Redeploy anything that reads the key at startup; many platforms apply new environment variable values only to new deployments. Don't send the new key over chat or email to the person who'll paste it in, or you're starting the next incident. Share it through your secret manager.

Minute 7–9: Look for abuse

A leaked key is an exposure; a used leaked key is a breach. Check what happened between the exposure time you wrote down and the moment you revoked:

  • OpenAI: the key's last_used_at in the project API key list (API reference) and the usage dashboard for spikes you don't recognise.
  • Stripe: open the key's request logs from the API keys page; Stripe sends you to Workbench, where you can see what the key did (Stripe Docs).
  • AWS: review CloudTrail for the key's activity, and look for new IAM users, new access keys, and compute running in regions you don't use.

What you're looking for: calls from IP addresses that aren't yours, resources or users you didn't create, charges, refunds or payouts you didn't make, and data reads at odd hours. OWASP's guidance is that incident responders need to answer who had access to the secret, when it was used and when it was last rotated (OWASP Secrets Management Cheat Sheet). If you find real abuse, escalate now: this is a security incident, and the attacker may have used the key to create other credentials that survive its revocation.

Minute 9–10: Contain the source

Only now clean up where it leaked, so the same value can't be found again and the next scan doesn't page you for an already-dead key:

  • Git: remove the file and rewrite history. GitHub recommends git-filter-repo (version 2.47 or later for its --sensitive-data-removal flag), and GitHub Support can remove cached views and pull request references when rotating isn't enough on its own (GitHub Docs).
  • Logs and CI output: delete or redact the log lines, and fix whatever printed the value.
  • Chat, tickets and docs: delete the message, and check exports and integrations that copied it.
  • Packages and images: if the key shipped inside a published npm package or a container image, publish a fixed version and deprecate or delete the old one.

After the first 10 minutes

The urgent part is over. Before you close the incident:

  1. Write down the timeline: exposure, detection, revocation, replacement, abuse check. It's short, and it's the evidence you'll want later.
  2. Close the hole. Turn on push protection for your repositories; GitHub's supported patterns table shows which key types it can block before they're pushed (GitHub Docs). Add a pre-commit hook that scans staged changes for keys.
  3. Shrink the blast radius of the next leak. Use restricted, per-environment keys, provider spend limits where they exist, and keys that change on a schedule, so a leaked value goes stale on its own.

How Keysquid fits in

Most of the ten minutes above is spent finding where a key is used and replacing it in each place by hand. Keysquid keeps that map for you: it knows which platforms each key was pushed to, so Rotate + revoke now mints the replacement, writes it everywhere and revokes the leaked key the moment the new one is live. Rotate everything does the same for every key in the workspace, with no grace period, for when a whole .env file got out, and a kill switch revokes a key without replacing it when stopping access matters more than uptime (revoke tools). The CLI adds a pre-commit hook (keysquid scan install-hook) that blocks commits containing keys.

Because values are encrypted to an agent you run in your own infrastructure, Keysquid itself never holds a copy of the key that leaked, or of its replacement; see the security model.

Whatever tools you use, keep the order: assume it's compromised, kill it, replace it, check for abuse, then clean up.

Frequently asked questions

I deleted the commit and force-pushed. Is the key safe now?

No. Copies can survive in clones, forks, cached views and pull requests, and anyone who saw the key already has it. Revoking or rotating the key is the only step that makes it worthless.

Should I revoke the key or rotate it?

For a public leak, revoke now, even if it causes a short outage, then ship the replacement. A planned overlap rotation, where the old key keeps working for a while, is for routine rotations, not for keys an attacker may already hold.

Will GitHub or the provider revoke a leaked key for me?

Sometimes. GitHub's secret scanning partner program notifies participating providers when their key formats appear in public sources, and some providers revoke or quarantine the key. Don't rely on it: act as if nobody else will.

The key only leaked into a private repo, a log or a Slack channel. Does this still apply?

Yes. Treat it as compromised. Everyone and every system with access to that place had the key, and private places get exported, backed up and breached.

How can I tell whether someone used the leaked key?

Look at the provider's records for that key: last-used times and usage for OpenAI, request logs for Stripe, CloudTrail for AWS. Unknown IP addresses, new resources or spend you don't recognise mean you have an incident, not just a leak.

Sources

  1. docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository
  2. docs.github.com/en/code-security/secret-scanning/secret-scanning-partnership-program/secret-scanning-partner-program
  3. docs.github.com/en/code-security/secret-scanning/introduction/supported-secret-scanning-patterns
  4. docs.stripe.com/keys
  5. docs.aws.amazon.com/IAM/latest/UserGuide/id-credentials-access-keys-update.html
  6. repost.aws/articles/ARoBXj63rWSt2Ww7XKlVV72g/how-aws-responds-to-exposed-credentials-and-how-you-can-protect-your-account
  7. developers.openai.com/api/reference/resources/organization/subresources/projects/subresources/api_keys
  8. cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html

For AI agents: this article is also available as Markdown.

What to do in the first 10 minutes after you leak an API key · Keysquid