A developer pushes a commit, then notices the file contained a live API key. They delete the file and push again. Problem solved? No. The key is still in the repository history, it may already have been copied, and it still works. The fix is not deleting the file. It is making the secret useless.
Secrets in code are one of the most common and most avoidable security incidents. Passwords, cloud access keys, database connection strings and API tokens get committed by accident, often in configuration files, test scripts or notebooks.
The scale is large. GitGuardian's State of Secrets Sprawl 2025 report counted 23.8 million new secrets leaked on public GitHub repositories in 2024, up 25% on the year before. Worse, it found that around 70% of secrets leaked in 2022 were still valid: they had been exposed but never revoked.
In October 2022, Toyota disclosed that part of the source code for its T-Connect service had been uploaded to a public GitHub repository by a subcontractor in December 2017. The code included an access key for a server holding customer email addresses and customer management numbers.
The repository was closed on 15 September 2022, and the key was changed two days later. According to reports of Toyota's disclosure, around 296,000 email addresses could have been accessed by anyone who found the key during those years, and Toyota said it could not completely rule out that a third party had done so.
GitHub's own guidance is clear: if the exposed data is a credential, the first step is to revoke and/or rotate it. Do this before anything else, including before cleaning the repository.
Once the secret is dead, look back at what happened while it was alive:
If you find misuse, this becomes a full incident: follow your incident response process, and assess whether personal data was accessed and needs reporting.
Revoking a key will break whatever legitimately depended on it. List every application, pipeline and service that used the secret, deploy the new one to each, ideally through a secrets manager or your CI/CD platform's secret store rather than a file, and confirm they work.
GitHub notes that once a credential has been revoked or rotated, that may be enough, and rewriting history may not be necessary. If the file also contained other sensitive data, or you want to remove the trace, GitHub recommends:
git-filter-repo, using version 2.47 or later for its --sensitive-data-removal option..gitignore for local configuration files such as .env, and provide a .env.example with placeholder values instead.Leaking a secret is a common mistake, and it should be treated as one: reported quickly and without blame. What turns it into an incident is the delay. Rotate first, check for misuse, then clean up, and put guard rails in place so the next mistake is caught before it is pushed.
Cyber Insight | Playbook Monday · Season 1
Making cybersecurity easier to understand, one issue at a time.
Step-by-step defender checklists for when something goes wrong.
Have a question or a suggestion? Prepare an email below. Feedback is private and is sent only when you press Send in your email app.
Likes and claps are your personal reactions on this device.
You can also email Poorna directly.
Your feedback stays private. Nothing is sent from this page automatically.
I started Cyber Insight because everywhere online people only talk about cybersecurity in technical terms — and most people are left without a proper understanding of how the digital world works. I work in cybersecurity, but I write here for everyone. No jargon. Just clear, honest explanations.