Join our Newsletter — 33% off our NHI Course
Home FAQ Threats, Abuse & Incident Response Why do leaked secrets in deleted commits still…
Threats, Abuse & Incident Response

Why do leaked secrets in deleted commits still create risk even when they are no longer visible in the main branch?

← Back to all FAQ
By NHI Mgmt Group Editorial Team Updated September 9, 2026 Domain: Threats, Abuse & Incident Response

Deleted commits can remain recoverable through Git provider metadata, pull request refs, or API-accessible history even after a branch is removed. That means a secret can be invisible in the repository UI yet still be retrievable by an attacker or scanner. The risk is exposure persistence, not just current branch visibility, so remediation depends on revocation, not deletion alone.

Why Deleted Commit Secrets Still Matter

A secret in a deleted commit is still a credential exposure problem because Git history is not the same thing as a visible branch tip. Once a token, key, or certificate has been committed, it can persist in refs, caches, forks, pull request metadata, mirrors, backups, and searchable provider history. That means the exposure window often outlives the branch cleanup that teams assume is “remediation.”

The practical issue is that visibility and recoverability are different. Removing a commit from the main branch may reduce casual discovery, but it does not reliably eliminate every copy, index, or derivative of that content. In secret management, revocation is the control that actually changes the value of the leaked credential. NHIMG’s The 2024 State of Secrets Management Survey found that the average time to mitigate a leaked secret is 36 hours, which shows how long exposure can persist when response is manual.

In practice, many teams discover the leak only after a scanner, an auditor, or an attacker has already accessed history that they believed was gone.

How Exposure Persists in Git Workflows

Git is designed to preserve history, which is useful for collaboration but risky for secrets. A deleted branch, rewritten commit, or merged pull request can still leave the secret reachable through object storage, branch protection artifacts, fork networks, cached clones, issue attachments, or provider APIs. If the repository platform has already indexed the content, the secret may remain discoverable even when the main branch no longer shows it.

This is why branch deletion is only a housekeeping step, not a security outcome. The response has to assume that the secret may already be copied elsewhere. That means rotating the credential, checking all places where it may have propagated, and invalidating any access path that the secret enabled. For code repositories, the right mental model is “recoverable until revoked,” not “safe once hidden.”

NHIMG’s Guide to the Secret Sprawl Challenge is useful here because it frames exposure as a lifecycle problem, not a single commit problem. External guidance from the OWASP Non-Human Identity Top 10 is also relevant when the leaked value authenticates a workload or service identity, because the exposure then becomes machine-access risk, not just code hygiene.

  • Search beyond the main branch for forks, tags, pull requests, and mirrored repositories.
  • Assume provider-side indexes and developer clones may retain the content after branch deletion.
  • Rotate or revoke the secret before relying on repository cleanup as a mitigation.
  • Verify whether the leaked credential has permissions that extend into production systems or automation.

These controls tend to break down in distributed development environments where many copies of the repository exist outside the original platform’s deletion boundary.

Where the Real Risk Boundary Actually Is

Tighter repository hygiene often increases operational overhead, because teams must coordinate Git cleanup with credential rotation, downstream access review, and incident triage. The main tradeoff is speed versus certainty: deleting history is fast, but proving that every recoverable copy is gone is slow and often impossible without broader containment.

There is also a common edge case where the secret is technically expired but still dangerous because the surrounding automation has not been updated. In that situation, the leaked value may no longer open one system, yet it can still expose environment names, role structures, or adjacent credentials that help an attacker pivot. Best practice is evolving toward treating every committed secret as a potential incident until you can prove the blast radius is contained.

This is especially important for internal repositories, which NHIMG research shows are far more likely to contain secrets than public ones. The issue is not that private repos are inherently unsafe; it is that teams often trust internal visibility controls more than they trust secret lifecycle controls. External confirmation of the broader governance problem is available in the NIST Cybersecurity Framework 2.0, which reinforces the need to manage risk across detection, response, and recovery rather than only at the point of exposure.

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 and MITRE ATT&CK address the attack and risk surface, while CIS Controls v8 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP Non-Human Identity Top 10NHI-01 — Secrets and Credential InventoryDeleted-commit secrets remain a machine-credential exposure problem.
NHI-03 — Credential Rotation and RevocationThe risk persists until the leaked secret is rotated or revoked.
Recommendation — Inventory exposed secrets and revoke any credential that can still authenticate. Rotate the exposed secret and invalidate all dependent access paths immediately.
CIS Controls v85.6 — Account ManagementLeaked secrets often map to service or automation accounts needing rapid removal.
6.3 — Data RecoveryRecovered Git history and backups can preserve exposed secret material.
Recommendation — Disable or reconfigure any account or service tied to the leaked secret. Verify backup, clone, and recovery paths do not retain reachable secret copies.
MITRE ATT&CKT1552 — Unsecured CredentialsCommitted secrets are recoverable credential material attackers actively seek.
Recommendation — Hunt for exposed credentials in history and remove the access they enable.

Practitioner Guidance

What to prioritise: Treat leaked secrets in deleted commits as a credential incident first and a repository cleanup task second. The first decision should be whether the exposed value can still authenticate anywhere, because that determines whether rotation, revocation, or both are required.

What to verify: Confirm whether the secret exists in forks, clones, cached build logs, pull request diffs, provider indexes, and backup copies before declaring the issue contained. If the credential was reused across environments, the incident scope should expand immediately rather than waiting for proof of abuse.

Common mistake: Teams often remove the visible commit and stop there. That response misses the real risk boundary, which is whether any retrievable copy still grants access or can be used to infer adjacent privileges.

Practitioner takeaway: The security decision is not whether the secret is still visible in the main branch; it is whether any recoverable copy still has value to an attacker or an automation path.

Deepen Your Knowledge

Sign up to our weekly newsletter — get 33% off our NHI Foundation Level Course

    NHIMG Editorial Note
    Reviewed and updated by the NHIMG editorial team on September 9, 2026.
    NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org