Part 1, Code · Step 9: Git history
Deleted from the code, and it still works
Deleted, but still working. Right after the merge, Sam deletes the feature/BILL-142-apple-pay branch, the usual cleanup, and Priya, a teammate, deletes the .env file from main. The latest version of the code is clean. But the commit that added the key is still in the code’s history on main, so every clone of the code still has it. And the key still works.
Why it matters. Deleting text does not turn a key off. Only the service that issued it can.
See it in the lesson Part 1 recap
This really happened: Truffle Security, 2024
Commits pushed to a fork stay reachable after the fork is deleted. Checking three widely forked repositories from large AI companies turned up 40 valid keys in deleted forks.
Why many code scanners miss old versions
- A normal full scan reads every commit still reachable from a branch or tag in the clone, including file contents and the commit message. It does not read pull request comments, issues, or gists.
- A commit that was merged is still reachable from the branch it landed on, so deleting the line later does not hide it.
- A deleted branch disappears from a fresh clone once nothing else points at those commits. Open source has a separate experimental GitHub scan for those deleted and hidden commits, including commits a fork can still reach. It needs a token and can take a long time.
- Forks are off unless the GitHub scan is told to include them. A clone of the main repository does not contain a fork’s own commits.
- CI jobs and the GitHub Action usually scan only the new commits. A shallow clone, the checkout action’s default, cannot see older versions.
- Some scanners check only the latest files. GitHub’s secret scanning does read full history, but only for the key types it knows.
Where the key still lives
- Main’s history: the merged commit still has the .env file with the key.
- Every teammate’s clone, and any tag that points at that commit.
- The pull request page: GitHub keeps a pull request’s commits even for a deleted branch, so the diff still shows the key.
- Forks: a fork made before the cleanup holds the commit too.
Try it with TruffleHog open source
Scans every commit still reachable from a branch or tag, including commit messages, so a deleted line is still found. A deleted branch is not in that clone once nothing else points at its commits. The experimental command trufflehog github-experimental --repo REPO_URL --object-discovery enumerates those deleted and hidden commits, including ones a fork can still reach.
trufflehog git file://.
Sources
- GitHub Docs, “Removing sensitive data from a repository”
- GitHub Docs, “About secret scanning”
- GitHub, actions/checkout README (default fetch-depth)
- TruffleHog README, “Scan a GitHub Repository for Cross Fork Object References and Deleted Commits”
- Truffle Security blog, “TruffleHog now finds all Deleted & Private Commits on GitHub”
- TruffleHog docs, “GitHub”
- TruffleHog docs, “Git”
- Truffle Security, “Anyone can Access Deleted and Private Repository Data on GitHub” (2024)
Keep going
- Try TruffleHog open source Scan a repository or a folder on your laptop.
- See TruffleHog Enterprise Continuous scanning, routing to owners, and re-checks.
- Talk to the team Ask how this would work in your environment.
More topics
- A key kept in a vault still gets copied out
- Bundled scanners and the noisy queue
- What sits behind a key: owner, reach, permissions, activity
- The owner chase: whose key is this?
- Which key to fix first
- Replace a key without breaking anything
- Proof it’s dead, time to fix, and what auditors ask for
- Keys in AI agents and AI training data
- Hosted or self-hosted: where the scanner runs
- Hooks, CI, history, chat, and builds: what each layer catches
- Keys outside the code: logs, vendors, and public files
- Live, dead, or unknown: triage the queue
- One key, three teams: rotate without an outage