Secrets leak through git history, not just the latest commit

$ cat blog/secrets-in-git-history.md
✓ secrets
✓ git
✓ incident response
5 min read
$ 

Deleting a secret from a file does not remove it from your repository. Git keeps history, so a key committed last month is still there in an old commit, fully readable to anyone who can clone the repo. Scanning only the current files misses it entirely.

Why "I already removed it" isn't enough

When you edit a file to delete an API key and commit, you've added a new commit — the old one with the key is untouched and still reachable. Anyone with the repository (including every fork and clone) can check out that commit and read the secret. For public repositories, assume automated scrapers found it within minutes.

What to actually do when a secret is committed

  1. Rotate first. Treat the credential as compromised and rotate it immediately. Removing it from history is secondary — rotation is what stops the bleeding.
  2. Then purge history if needed (tools like git filter-repo), and force-push. Coordinate with your team, since this rewrites history.
  3. Check what the secret could reach. Scope the blast radius: what did that key have access to, and was it used?

Scan history, not just the tree

A good secret scan looks at the full git history, not only the working tree. OpenRouting doesn't do this yet: a scan reads the files at the commit you scan, so a key that was "removed" but never rotated won't show up. If you need history covered today, run a history-aware secret scanner over a full clone of the repository, and treat any key that was ever committed as exposed.

What OpenRouting does cover is the files you scan, including the files a pull request changes, so a new key can be caught before it merges. Semgrep's secret rules flag the value, and the value is redacted before anything is sent to an AI model for review: the model sees [REDACTED], never the secret.

Prevent the next one

  • Keep secrets in a secrets manager or environment variables, never in committed files.
  • Add a pre-commit secret scan so leaks are caught before they're pushed.
  • Scan on every push so a slip is found in minutes, not months.

The cheapest leak to handle is the one that never gets committed. The second cheapest is the one you find today instead of after an incident.

Questions

Does deleting a secret from a file remove it from git?

No. Deleting it adds a new commit, and the old commit with the key is untouched. Anyone with the repository, including every fork and clone, can check out that commit and read the secret.

What should I do first if I committed an API key?

Rotate it immediately and treat it as compromised. Purging it from history comes second, because rotation is what stops the bleeding; then check what the key could reach and whether it was used.

How do I remove a secret from git history?

Rotate the credential first, then rewrite history with a tool such as git filter-repo and force-push. Coordinate with your team, since this rewrites history for everyone.

Does OpenRouting scan git history for secrets?

Not yet. A scan reads the files at the commit you scan, so a key that was removed but never rotated won't show up. It does flag secrets in the scanned files, including those a pull request changes, and redacts the value before any AI review.

Keep reading