Because deleting a secret from the latest file does not guarantee it disappears from version history, platform databases, or clones already made elsewhere. If the secret was valid when committed, anyone who captured it earlier may still be able to use it until it is revoked.
Why This Matters for Security Teams
Secrets in Git history are a long-tail risk because version control is designed to preserve change, not to erase exposure. Once a credential lands in a commit, it can persist in forks, mirrors, backups, build logs, and developer clones even after the latest branch is cleaned up. That turns a single mistake into a distributed exposure problem, especially when the secret authenticates a workload, CI runner, or cloud API rather than a human user. NHI Management Group’s view is that this is a lifecycle failure, not just a code hygiene issue.
The scale is not theoretical. GitGuardian found that 64% of valid secrets leaked in 2022 are still valid and exploitable today in The State of Secrets Sprawl 2026, which is why detection alone does not close the risk. The practical lesson is reinforced in the CI/CD pipeline exploitation case study and the Guide to the Secret Sprawl Challenge, both of which show how quickly one exposed secret becomes a reusable foothold. Current guidance from the NIST Cybersecurity Framework 2.0 and the OWASP Non-Human Identity Top 10 points to governance, identification, and response as essential controls, not optional extras.
In practice, many security teams discover the problem only after a secret has already been harvested from history and abused outside the original repository.
How It Works in Practice
Git history creates risk through persistence and replication. A secret may be removed from the main branch, but the commit object still exists unless the repository is rewritten, every clone is cleaned, and every downstream cache, mirror, and artifact store is addressed. That is why revocation must happen as soon as exposure is confirmed. The authoritative sequence is simple: detect the secret, rotate or revoke it, invalidate dependent sessions, then remove it from history where feasible. For NHI credentials, especially tokens used by automation, the revocation step matters more than the cleanup step.
This is also where workflow design matters. Static credentials embedded in code are the hardest to secure because they survive long enough to be copied into places that are outside the developer’s control. Short-lived secrets, JIT issuance, and workload identity reduce that exposure window. For workload-based authentication, cryptographic identity from systems such as SPIFFE or OIDC is stronger than shared secrets because it binds access to the workload, not to a string that can be pasted into a commit. That aligns with the direction of the OWASP Non-Human Identity Top 10 and the NIST Cybersecurity Framework 2.0, which both emphasise limiting blast radius and improving recovery.
- Prefer dynamic credentials with short TTLs over long-lived static secrets.
- Separate detection from response so revocation can occur automatically.
- Scan commits, tags, release branches, and mirrored repositories, not just main.
- Assume a secret may already exist in clones, CI caches, and tickets outside Git.
Git history risk is especially severe when secrets are reused across environments or tied to privileged automation, because one commit can expose multiple systems at once. These controls tend to break down when organisations allow shared tokens across CI/CD, SaaS integrations, and cloud automation because a single leak becomes a cross-platform compromise.
Common Variations and Edge Cases
Tighter secret management often increases delivery overhead, so organisations have to balance developer speed against the cost of emergency rotation and historical cleanup. That tradeoff is manageable for mature teams, but it becomes harder in mono-repos, release-heavy environments, and projects with many external contributors. There is no universal standard for how far to rewrite history after a leak; best practice is evolving, and the right answer depends on whether the repository is public, mirrored, or already consumed by downstream tooling.
One important edge case is that a secret may be technically removed from Git but still remain live because it was copied into a CI variable, incident note, chat thread, or ticketing system. That is why the broader NHI sprawl problem matters as much as the repository itself. NHIMG research on Shai Hulud npm malware campaign and Reviewdog GitHub Action supply chain attack shows how quickly secrets move from one system into many. Internal findings in 52 NHI Breaches Analysis also show that duplication and overuse make historical exposure harder to contain.
For regulated or high-assurance environments, the safest pattern is to treat any leaked secret as compromised until proven otherwise, then verify whether the credential was duplicated, embedded in automation, or used to mint additional tokens. That approach is slower, but it avoids false confidence from deleting only the latest file revision.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Non-Human Identity Top 10 address the attack and risk surface, while NIST CSF 2.0 and NIST AI RMF set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Non-Human Identity Top 10 | NHI-03 | Addresses secret rotation and exposure response for non-human identities. |
| NIST CSF 2.0 | PR.AC-4 | Least-privilege access reduces blast radius when Git history exposes credentials. |
| NIST AI RMF | Risk governance applies when automation or AI systems depend on long-lived secrets. |
Use AI RMF governance to require ownership, monitoring, and response for secret-backed automation.
Related resources from NHI Mgmt Group
- Why do non-human identities create more risk than many human accounts?
- Why do non-human identities create more remediation risk than many human accounts?
- What is the biggest long-term risk of unmanaged NHIs multiplying at exponential rates?
- What is secrets sprawl and why does it create security risk?