If an API key leaks, revoke or replace it first, then work out what it could reach and whether anyone used it, and only then clean up where it was exposed. Speed matters more than tidiness: until the key stops working, every copy anyone has is live.

This order differs from a scheduled rotation, where you keep the old key running for a while. In an incident, you accept a short outage to cut off the attacker.

What counts as a leak?

Treat a key as leaked if it appeared anywhere you do not control: a public or shared repository, a log, a screenshot, a support ticket, a chat, a pasted prompt, a package you published, or a machine that ran malicious code. Assume a leak, not just a possible one, when a supply-chain incident touched your build or laptop. The records on /incidents show the pattern: after the 2025 tj-actions/changed-files compromise, the advice was to treat every secret available to the affected jobs as exposed, and after the Nx compromise the advice was to rotate GitHub, npm and cloud credentials.

What are the steps?

  1. Revoke or replace the key now. Do not wait to investigate. Use the provider’s fastest path (see below). If the key is in a live system, expect that system to fail until you deploy the replacement, and accept that.
  2. Create a narrower replacement. Issue the new key with the least scope that works, and a short expiry where the provider allows. See least privilege.
  3. Deploy the replacement and verify. Update your secrets store and redeploy. Confirm the service works.
  4. Find out what the key could do. List its scopes, projects and permissions. This defines the blast radius.
  5. Review activity. Check logs for requests you do not recognize, from unfamiliar addresses, at odd times, or against resources you did not expect.
  6. Undo anything unauthorized. Remove resources, users, tokens, webhooks or keys you did not create.
  7. Remove the exposed copy. Delete the key from the log, ticket, message or file where it appeared. This is cleanup and does not protect you on its own, because copies may exist.
  8. Find the cause and close it. Work out how it leaked and fix that, or it will happen again.
  9. Write it down. Note times, actions and the root cause.

How do I revoke the key at common providers?

Steps are summarized from each provider’s documentation.

  • GitHub. Delete the token immediately under Settings, Developer settings, Personal access tokens. GitHub advises rotating the credential first. Create a replacement with narrower permissions, review the account’s security log and the repositories the token could reach, and check the secret scanning alert on the repository’s security tab if it was pushed. Rewrite Git history only if needed. Note that classic ghp_ tokens reach every repository the account can access, so they are more damaging than a repository-scoped fine-grained token. See /keys/github.
  • AWS. Deactivate the key straight away with aws iam update-access-key and status Inactive. Review CloudTrail for activity by that access key ID and remove any resources, users, roles or keys you did not create. Then delete the key and create a replacement stored in a secrets manager. If AWS attached the AWSCompromisedKeyQuarantine policy to the user, remove it only after the key is replaced and the account is clean. See /keys/aws.
  • Stripe. Rotate the key from the API keys page and choose Now as the expiration so the exposed key stops working. Check the key’s request logs, update your secrets store and redeploy, and attach an access policy to the replacement. See /keys/stripe.
  • GitLab. Revoke the token from the ellipsis menu, create a replacement with narrower scopes and a short expiry, review recent activity for the user, project or group, and replace any token pasted into issues, comments or logs. See /keys/gitlab.
  • Others. Every provider page under /keys has the revoke steps for that service. If you do not know which provider a key belongs to, /tools/api-key-identifier can help recognize it from its prefix.

Is deleting the commit enough?

No. A pushed key must be considered copied. Anyone who cloned or forked the repository, or who read it while it was public, may already hold it, so removing it from the latest commit does nothing to protect the account. Revoke first. After that, rewriting history is optional hygiene, and the GitHub guidance in the dataset describes it as slow and often unnecessary once the token is revoked.

What if you cannot tell whether it was used?

Assume it was. Rotate anything the key could have read, including secrets stored in the services it accessed, and consider the data it could have read as exposed. Keep logs for as long as your provider retains them and note the retention window, because some evidence ages out.

How do I prevent a repeat?

  1. Scan before you push. Add a secret scanner as a pre-commit hook and in CI, and enable your host’s secret scanning. See secret scanning.
  2. Move to short-lived credentials wherever possible, so a leak expires by itself. See secrets in CI/CD pipelines.
  3. Stop keeping keys in files that tools and agents read. See how to store API keys safely and keeping env files away from AI agents.
  4. Rehearse rotation. A practiced rotation turns a leak into a routine task.
  5. Scope keys narrowly, so the next leak has a small blast radius.

Where does BotPassword fit?

BotPassword keeps keys encrypted and hands them only to the specific command or request that needs them, so there is less loose plaintext to leak, and it runs rotation as a tracked sequence an agent can request without seeing the value. It does not replace the response steps above: revoking and checking for misuse remain the first jobs.

Frequently asked questions

What is the first thing to do if I pushed an API key to GitHub?

Revoke or rotate the key at the provider immediately. GitHub advises rotating the credential first, because anyone who copied it can still use it after you delete the commit.

Do I need to remove the key from git history?

Only if you need to, and only after the key is revoked. Rewriting history is slow and often unnecessary once the key no longer works.

How do I know if someone used my leaked key?

Check the provider's request logs, audit trail or billing for activity you do not recognize. AWS offers CloudTrail records for access key activity, and Stripe shows request logs per key.

Should I tell anyone?

Tell your team and security contact so everyone is working from the same facts. If customer data or contractual obligations are involved, your legal or compliance team decides on notification.

More guides

Give agents access. Keep the keys.

BotPassword is in early access. Request an invite and we'll email you when your spot opens.