Season 1 Part of Playbook Monday · Episode 06 of 10
View all 10 episodes →
Playbook Monday · Episode 06 · Secrets Management · GitHub · API Keys · Playbook · May 3, 2027 · 9 min read

A Secret Leaked in a Public Repository: Rotate First, Clean Up Second

Playbook Monday · Ep 06 Secrets Management GitHub API Keys Playbook · 9 min read
💬 Feedback
23.8m
Secrets leaked on public GitHub in 2024
Up 25% on the previous year, according to GitGuardian's State of Secrets Sprawl 2025
~70%
Of secrets leaked in 2022 still valid
GitGuardian found most were never revoked, leaving access open years later
~5 years
A Toyota access key sat on GitHub
Exposing a server holding nearly 300,000 customer email addresses until 2022

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.

Deleting a leaked secret from your code does not un-leak it. Only revoking it does.
At a glance 1. Revoke or rotate the secret, immediately
2. Check whether it was used by anyone else
3. Update everything that legitimately used it
4. Clean the repository history, if still needed
5. Find out why it happened and prevent a repeat

A Real Case: Five Years on GitHub

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.

Step 1: Revoke or Rotate the Secret, Now

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.

  • Assume it is already compromised. Automated scanners watch public repositories continuously. You cannot know who copied it.
  • Revoke, do not just add a new one. Creating a new key while leaving the old one active solves nothing.
  • Treat private repositories seriously too. GitGuardian found secrets in about 35% of the private repositories it analysed. A leak to a private repository is still a leak to everyone with access to it, and to anyone who later compromises it.

Step 2: Check Whether It Was Used

Once the secret is dead, look back at what happened while it was alive:

  • Cloud keys: review the provider's audit logs (for example AWS CloudTrail, Azure activity logs or Google Cloud audit logs) for activity using that key, especially from unfamiliar IP addresses, new resources being created, or data being read or copied.
  • API tokens: check the service's access logs and usage dashboards for unusual volume or locations.
  • Database credentials: review connection logs and look for large queries or exports.
  • Billing: unexpected cloud costs are often the first sign that a leaked key is being used, for example to run cryptocurrency mining.

If you find misuse, this becomes a full incident: follow your incident response process, and assess whether personal data was accessed and needs reporting.

Step 3: Update Everything That Used It

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.

Step 4: Clean the History, If Still Needed

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:

  • Rewrite the history locally with git-filter-repo, using version 2.47 or later for its --sensitive-data-removal option.
  • Understand the side effects. Rewriting history changes commit hashes, breaks signatures and open pull requests, and collaborators can accidentally reintroduce the data by pushing from old clones.
  • Remember the copies. GitHub warns that the commits may still be accessible in clones, forks, cached views and pull requests. GitHub Support can remove cached views and pull request references on GitHub, but cannot reach forks or other people's clones.
Do not do it in the wrong order Spending an hour rewriting git history while the key is still valid is the most common mistake. Rotation takes minutes and removes the risk. History cleaning is housekeeping.

Step 5: Stop It Happening Again

  • Turn on secret scanning and push protection. GitHub enabled push protection by default for pushes to public repositories in 2024, which blocks many recognised secret types before they reach GitHub. Make sure it is enabled for your organisation's repositories, including private ones where available.
  • Use a secrets manager. Applications should fetch secrets at runtime from a vault or cloud secret store, not read them from files in the repository.
  • Add pre-commit scanning on developer machines, so secrets are caught before they are even committed.
  • Use .gitignore for local configuration files such as .env, and provide a .env.example with placeholder values instead.
  • Prefer short-lived credentials. Workload identity and temporary tokens limit the damage if something does leak.
  • Include contractors. The Toyota leak came from a subcontractor's repository. Your secret-handling rules should apply to everyone who works on your code.

Final Thoughts

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.

The moment a secret is pushed, it is no longer a secret. Rotate it, then tidy up.

Sources and Further Reading

Cyber Insight | Playbook Monday · Season 1

Making cybersecurity easier to understand, one issue at a time.

Season 1

Playbook Monday · All 10 Episodes

Step-by-step defender checklists for when something goes wrong.

PS
Poorna Sujampathi Rathnayaka
Writer · Cyber Insight · Digital Literacy

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.