Leaked an API Key on GitHub? What to Do in the First Hour
Leaked an API key? The first-hour playbook: revoke, replace, check the logs and clean up, with exact steps for AWS, Stripe, OpenAI and GitHub keys.
If you leaked an API key on GitHub, revoke or rotate it at the provider right now, before you touch the code: deleting the commit does not stop anyone who already copied it. Then issue a replacement with less access, check the provider's logs for use of the old key, and only then clean up the repository.
This is the first-hour playbook, with exact steps for the four keys that leak most often: AWS, Stripe, OpenAI and GitHub. It comes from Strac, a Y Combinator-backed data security company trusted by enterprises, which has spent five years finding exposed credentials in code, SaaS apps and AI tools. Bookmark it before you need it.
Every API key leak response follows the same four steps, whatever the provider. The order matters more than the speed of any single step:

Revoke first because it is the only step that stops an attacker who already has the key. Replace next, so production keeps running; expect a short outage if you cannot deploy the new key quickly, and accept it. Investigate by reading the provider's own logs, not your application logs, because an attacker uses the key directly against the provider's API. Contain and record: remove anything created with the key, and write down the timeline. That record is what your auditor and your customers will ask for.
Public GitHub is watched constantly, by defenders and attackers. In a Unit 42 test, AWS attached a quarantine policy to an exposed key about ten seconds after it was pushed to a public repository. Automated scanners run by attackers are not much slower, and cloud keys can be turned into crypto-mining instances or data theft within minutes. Some of the response is automatic:

GitHub's secret scanning partner program tells many providers when their key format appears in a public repo. That is a safety net, not a plan. It does not cover private repos, other git hosts, CI logs, Slack messages, Google Docs or AI chats, which is where most keys leak inside a company.
An AWS key starting with AKIA is a long-lived IAM user key and the most expensive one to leak. AWS may attach the AWSCompromisedKeyQuarantineV3 policy, which blocks some high-risk actions, but the key keeps working. Deactivate it yourself, then look at what it did:
# 1. who owns it (run with the leaked key, or look it up in the console)
aws sts get-caller-identity
# 2. deactivate now, create the replacement
aws iam update-access-key --user-name USER --access-key-id AKIAEXAMPLE --status Inactive
aws iam create-access-key --user-name USER
# 3. what did it do? (management events, last 90 days, per region)
for r in $(aws ec2 describe-regions --query "Regions[].RegionName" --output text); do
aws cloudtrail lookup-events --region "$r" \
--lookup-attributes AttributeKey=AccessKeyId,AttributeValue=AKIAEXAMPLE \
--query "Events[].[EventTime,EventName]" --output text
done
# 4. once the replacement is deployed
aws iam delete-access-key --user-name USER --access-key-id AKIAEXAMPLELook for new IAM users, roles or access keys, EC2 instances in regions you do not use, new Lambda functions, and changes to S3 bucket policies. Attackers often create a second set of credentials first, so deleting the leaked key alone may not lock them out. Then remove the quarantine policy and, longer term, replace IAM user keys with roles; our AWS security checklist covers how.
A Stripe key starting with sk_live_ can create charges, issue refunds and read customer data. In the Dashboard, go to Developers, then API keys, and roll the key. Choose an expiration of Now: Stripe deletes the old key immediately and the new one works at once. A delayed expiration keeps the leaked key alive, so only use one if you cannot deploy within minutes, and keep it short.
Then review recent activity in the Dashboard for refunds, payouts, new webhook endpoints or API calls you do not recognize. When you issue the replacement, use a restricted key (rk_live_) with only the permissions that service needs, so the next leak is smaller.
Would you know today if a live key was sitting in your git history?
Book a demo of Strac secret scanning · Run a free security scan
OpenAI keys start with sk- and are billed to your account, so the usual abuse is someone else running up your bill. OpenAI disables keys it detects on the public internet, but do not wait for it. In the API keys page of the OpenAI platform, delete the key, then create a new one scoped to a single project. Check the usage dashboard for spikes or models you do not use, and set a project budget so a future leak has a ceiling. The same steps apply to Anthropic, Gemini and other model provider keys, which are popular targets for resale.
GitHub automatically revokes personal access tokens, OAuth tokens and GitHub App tokens that are pushed to a public repository or gist. In a private repo, a log or a chat, nothing happens automatically. Revoke the token under Settings, Developer settings, Personal access tokens. Then check your security log and, for organization access, the organization audit log for repositories cloned, settings changed, or new deploy keys and webhooks. A leaked token with repo scope means every private repo it could reach should be treated as read, including any secrets inside them. Replace it with a fine-grained token with an expiry, or a GitHub App.
| Provider | Key looks like | Revoke | Check |
|---|---|---|---|
| AWS | AKIA... | IAM, deactivate then delete access key | CloudTrail by access key ID, all regions |
| Google Cloud | Service account JSON key | gcloud iam service-accounts keys disable | Cloud Audit Logs for the service account |
| Azure | Client secret on an app registration | Delete the secret in Entra ID | Entra sign-in logs for the service principal |
| Stripe | sk_live_... / rk_live_... | Roll key, expiration Now | Dashboard activity and API logs |
| OpenAI / Anthropic | sk-... / sk-ant-... | Delete key in the console | Usage by key or project |
| GitHub | ghp_... / github_pat_... | Revoke in Developer settings | Security log and org audit log |
| Slack | xoxb-... / xoxp-... | Regenerate the token in app settings | Workspace access logs |
| Twilio / SendGrid | Account SID + auth token / SG.... | Rotate auth token / delete API key | Usage and message logs |
Most leaked API keys inside a company never touch a public repo. They are pasted into a Slack channel to unblock a teammate, saved in a Google Doc runbook, attached to a Jira ticket, printed into a CI log, or shared with an AI assistant while debugging. The playbook is the same: revoke, replace, investigate, record. What changes is that nobody tells you. There is no partner program for a Slack message, and the key can sit there for years, readable by every new hire and every integration with access to the channel.
Deleting the message is worth doing, but it is cleanup, not remediation, for the same reason deleting a commit is: exports, search indexes and anyone who already read it still have the key. Finding these leaks takes a scanner that reads SaaS apps as well as code, which is the gap a git-only tool leaves open.
You cannot promise a key will never leak. You can make sure a leaked key is worth little. Give every key the narrowest scope the service needs: restricted Stripe keys, project-scoped model keys, fine-grained GitHub tokens, IAM policies limited to named resources. Prefer credentials that expire on their own, such as IAM roles, workload identity and OIDC federation from CI, over long-lived keys. Put spending limits on anything billed per call, and set alerts that fire on unusual use, such as AWS budget alerts or GuardDuty findings. Restrict keys by IP address where the provider supports it. Each of these turns a future incident from an emergency into a chore.
Once the key is dead, remove it from the code and replace it with a reference to a secrets manager. Rewriting history with git filter-repo is optional: it does not un-leak anything, it disrupts everyone with a clone, and forks keep the old history. Do it for hygiene if you like, never instead of revoking. Then add the controls that stop the next one, a pre-commit hook and a pull request check, which our guide to hardcoded secrets sets up step by step, along with API key storage and rotation practices.
GitHub push protection blocks a git push that contains a recognized secret and makes the developer either remove it or record a reason for bypassing. It is on by default for public repositories, and organizations can enable it for private ones. It only knows the key formats GitHub supports and it can be bypassed, so pair it with a pre-commit hook on laptops and a scanner that also reads history and the places outside git where keys end up.
A leaked key is a security incident, even a small one, and SOC 2 auditors check that incidents are logged and handled. Record when the key leaked, when you found it, when it was revoked, what the logs showed and what you changed. Keep it short and factual. If customer data could have been reached, involve whoever owns your incident response and breach notification decisions, because some contracts and laws have notification deadlines. With Strac, the finding, the rotation and the closure are saved as evidence automatically, so the record exists without anyone writing it up.
The best API key leak is the one you find first. Strac scans every repo and its full git history, including notebooks, Kubernetes secrets and Terraform state, and checks each key with a read-only call to see whether it still works, so live keys come first and dead test values do not bury them. It fails pull request checks when a new secret appears, gives the exact rotation steps for each key type, and stores only a hash and a masked preview, never the secret itself:

Because Strac started as a data security company, the same platform finds keys pasted into Slack, Google Workspace and AI tools, the places a git-only scanner never sees. Our guide to secret scanning explains how history scanning works, and the wider program is covered in application security posture management. Strac's free scan checks up to 10 GitHub repos and their full history: run it here, or see how Strac secret scanning works.

Find every leaked key in your code and history, and know which ones still work.
Book a demo of Strac secret scanning · Run a free security scan
Revoke or rotate the key at the provider before anything else. Deleting the file or the commit does not stop anyone who already copied the key, and automated scanners copy keys from public repos within minutes. Once the old key is dead, replace it, check the provider's logs for use you do not recognize, and then clean up the code.
No. The key stays in git history, in every clone and fork, and in any cache or scanner that already saw it. Rewriting history is optional hygiene once the key is revoked; it is never a substitute for revoking it.
Often within minutes for public repositories. Attackers run automated scanners against new public commits, and cloud keys are a favorite target because they can be turned into crypto mining or data theft straight away. Treat any key that touched a public repo as compromised.
Yes, for many providers. GitHub secret scanning recognizes key formats from AWS, OpenAI, Stripe, Slack and many others, and its partner program notifies the provider when one appears in a public repo. GitHub revokes its own tokens automatically. Private repos, other git hosts, Slack and docs are not covered by that program.
Rotate it anyway. Everyone with access to the repo, past and present, and every laptop and CI system with a clone now has the key. Private repos also get forked, mirrored and pasted into tools, so a private leak is lower urgency than a public one but still a leak.
.avif)
.avif)
.avif)
.avif)
.avif)


.gif)

