Private Repos Made Public by Mistake: Damage Control Steps

Private Repos Made Public by Mistake: Damage Control Steps

A private repo made public by mistake is one of the few incidents where the clock starts before anyone on the security team knows there is a problem. Sometimes a developer flips the visibility toggle to get GitHub Pages working, and sometimes a migration script defaults to public. Either way, the source code, the full commit history and every secret ever committed are open to anyone watching. This article covers the damage control steps that reduce harm: sizing the exposure window, rotating credentials in the right order, finding copies and deciding whether you have a reportable breach.

What Happens in the First Minutes of Exposure

Public GitHub activity is never quiet. Making a repository public generates a PublicEvent in the GitHub events API. Projects like GH Archive record that event stream every hour. Both researchers and criminals run scrapers that pull new public content around the clock and check it with regex patterns and entropy checks.

Honeypot experiments with planted AWS keys have repeatedly recorded the first abuse attempts within minutes. So a repo that was exposed for 40 minutes on a Friday afternoon should be treated as fully harvested. An experienced incident responder starts from that assumption, and every later decision follows from it.

Here is a typical case. A platform engineer on a 12-person team needs a quick docs site. The organization is on GitHub Free, where Pages only works on public repos, so the internal infrastructure monorepo goes public “for a minute.” Three hours later, a contractor asks why they can see Terraform state files. By then the history contains a Stripe key, a production PostgreSQL connection string from 2022 and a Slack webhook.

The Myth That Switching Back to Private Fixes It

The most common misconception is that switching the repo back to private undoes the exposure. It does not. Anyone who cloned the repo has the full history on their own machine, and no GitHub setting can reach it.

Forks are the second problem. When a public repository is made private, GitHub splits its public forks into a separate network, and those forks stay public under their owners’ accounts. Truffle Security published research in 2024 showing that commits from deleted forks and deleted repositories can stay reachable by their commit hash through the fork network. GitHub considers this expected behavior. The mechanics are covered in more depth in how deleted secrets survive in forked copies.

Damage Control Steps for a Private Repo Made Public

Switch the repo back to private first. It takes seconds and stops new harvesting. Next, a seasoned incident lead opens the organization audit log and filters on the repo.access action. That action records every visibility change, with the timestamp and the account that made it, which gives you the exact exposure window. Also screenshot the Insights → Traffic page. It shows clones and unique cloners for the past 14 days, so the data disappears if you wait two weeks.

Then work through the rest in this order:

1. Scan every branch and tag across the full history, not just the current default branch.
2. Revoke and rotate every credential found, starting with the ones that give the most access.
3. Search provider logs for any use of the exposed keys during and after the window.
4. Review issues, the wiki, GitHub Actions logs and release artifacts, which were public too.
5. Decide on history rewriting and notification only after steps 1-4 are done.

For the scan, run gitleaks or TruffleHog against the full clone. TruffleHog’s verification mode is especially useful because it shows which keys are still live, and live keys go to the top of the queue. The same approach is explained further in scanning git history for secrets you already deleted.

Rotate in order of blast radius. Start with cloud IAM keys, then CI/CD tokens and deploy keys that can push code, then database credentials, and finally SaaS API keys and webhooks. AWS may automatically attach a quarantine policy to a key it detects as public. That policy blocks only some actions, so delete the key anyway. Then check AWS CloudTrail, the Azure Activity Log or GCP Cloud Audit Logs for calls from unfamiliar IP addresses or ASNs.

Rewriting history with git filter-repo or BFG Repo-Cleaner comes last. Once a secret has been exposed, rewriting changes nothing about the risk – only rotation does that. Rewriting still prevents the next accidental exposure, though. After force-pushing, ask GitHub Support to purge cached views and pull request refs, which a force push does not remove.

Finding Copies That Outlive the Fix

Pick three or four strings that only appear in your code, such as an internal hostname, a distinctive comment or a private package name. Search for them on GitHub code search, GitLab and the main paste sites. Software Heritage crawls public GitHub repos regularly and may have archived yours during the window. Contact them directly about removal.

If you find copies on GitHub under other accounts, a DMCA takedown notice for code you own usually gets them removed within 1-3 business days. Keep monitoring for at least 90 days. Leaked code often turns up again weeks later in a fresh repo or a forum post.

Common Mistakes During Cleanup

The most frequent mistake is rotating only the secrets visible in the current branch. A database password committed in 2021 and “removed” in 2022 is still in the history, and attackers parse history first because that is where forgotten credentials sit.

The second mistake is rewriting history before scanning it. Teams in a hurry run BFG, force-push and destroy the record of which secrets existed. They then rotate from memory and miss two of them.

The third mistake is trusting a fork count of zero. Clones never appear as forks, and the Traffic page shows how many people cloned, not who they were. Creating a new access key without deactivating the old one also happens more often than anyone admits, because AWS allows two active keys per user.

When the Standard Playbook Does Not Apply

On GitHub Enterprise Server behind a VPN, “public” means visible to every user of that instance, not to the internet, unless public mode is enabled. Treat that as an insider exposure. It still requires rotation, but forensic urgency and notification duties are much lower. The “internal” visibility setting on GitHub Enterprise Cloud works the same way: it reaches only enterprise members.

Regulated environments change the timeline. If test fixtures contained real customer records, the GDPR 72-hour notification clock may already be running. HIPAA and sector rules add their own deadlines, which are mapped in regulatory reporting timelines. For teams under 10 people with no dedicated security staff, the priority is simple: rotate everything within the first hour and accept imperfect forensics.

FAQ

How quickly do attackers find secrets in a repository made public by mistake?
Often within minutes. Automated scrapers follow the GitHub public events stream, so even a short exposure window should be treated as a full compromise of every secret in the history.

Does deleting the repository remove the exposure?
No. Clones, forks and archived copies are unaffected. Deleting the repo also makes your own investigation harder, because Traffic data and the commit context are gone with it.

Do we have to notify regulators if only source code was exposed?
Usually not, as long as no personal data was in the repo and logs show no unauthorized use of exposed credentials that give access to personal data. Customer contracts may still require you to tell them, so check your data processing agreements.

Summary: Rotate First, Investigate Second

Switch the repo back to private, but treat every secret in its history as burned. Capture the audit log entry and the Traffic data before they expire. Then scan the full history, rotate by blast radius, check provider logs and hunt down copies. Rewriting history only cleans up for the future. Rotation and log review are the steps that actually contain the incident.