Exposed Git Secrets: How to Find and Revoke Leaked Credentials

Leaked API keys, tokens and passwords in code repositories can create immediate access risks. Learn how to find exposed Git secrets, revoke credentials and prevent repeat leaks.

Exposed Git secrets can give an unauthorised person access to cloud services, applications, source code or business data. API keys, access tokens, passwords and private keys may be committed accidentally, copied into logs, or left in older repository history. Removing the visible string is not enough: teams must treat a potentially valid secret as compromised until its owner or provider confirms it has been revoked.

Australia’s cyber security guidance warns that online code repositories are being targeted to find secrets, obtain access to private code bases and support further attacks. Organisations should treat repository exposure as an access-control incident, not simply a code-clean-up task.

What counts as an exposed Git secret?

A secret is sensitive authentication material that should not be publicly accessible or stored unprotected in source code. Examples include:

  • Cloud-provider access keys and service account credentials.
  • API tokens for SaaS platforms, payment services and internal applications.
  • Database connection strings containing usernames or passwords.
  • SSH keys, signing keys and private certificates.
  • Application passwords, webhook secrets and credentials in configuration files.

A repository can expose a secret even if the current version looks clean. Credentials may remain in earlier commits, branches, tags, forks, pull requests, issue comments, build logs or release artefacts.

Why deleting a secret from code is not enough

Git records change history. A credential removed in a later commit may still be recoverable from an earlier commit or another copy of the repository. Public exposure can also be copied quickly, so teams should not assume a secret is safe because it was visible for only a short period.

Prioritise the credential itself first. History rewriting can help reduce accidental rediscovery, but it does not invalidate a key that may already have been copied.

How to find exposed credentials

1. Inventory repositories and access paths

List organisation-owned repositories, archived projects, personal forks used for work, package registries and automated build systems. Confirm who owns each repository and whether it contains production credentials or privileged deployment access.

2. Scan current files and repository history

Use an approved secret-scanning tool to check tracked files, all relevant branches and historical commits. Include configuration files, infrastructure-as-code, scripts, notebooks and deployment manifests. Where supported, scan pull requests and other collaboration content as well.

3. Triage findings safely

Validate findings without copying secrets into tickets, chat messages or reports. Determine the credential type, owner, permissions, likely exposure window and systems it can access. Check provider-side activity logs for unexpected use where available. A pattern match is not always a valid credential, but uncertainty should be resolved promptly.

4. Check for related exposure

Search for other copies of the same credential in repositories, CI/CD variables, developer workstations, deployment logs and configuration stores. Look for additional credentials committed in the same change. Do not publish the secret value in incident notes or evidence screenshots.

Response checklist: revoke, investigate and verify

  1. Revoke or rotate the credential. Use the issuing service’s supported process. If possible, replace it with a new credential stored in an approved secrets manager.
  2. Reduce access. Review permissions and remove excessive privileges. Prefer short-lived credentials or workload identity where the platform supports them.
  3. Investigate use. Review authentication, API, cloud and repository audit logs for suspicious activity during the possible exposure period.
  4. Replace dependent configurations. Update applications and deployment pipelines, then confirm legitimate workloads continue to function.
  5. Clean up copies. Remove the exposed value from active files and assess whether repository-history remediation is necessary. Coordinate with collaborators before rewriting shared history.
  6. Verify closure. Re-run scans, confirm the old credential is invalid, check for residual copies and record evidence of remediation.

How to prevent secrets leaking again

  • Enable secret scanning and push protection where available and appropriate.
  • Store credentials in a managed secrets service rather than source files or committed environment files.
  • Use least-privilege access, expiry dates and routine rotation for sensitive credentials.
  • Apply pre-commit checks and CI pipeline scanning, while keeping server-side scanning as an additional control.
  • Restrict repository permissions and protect critical branches.
  • Include forks, archived repositories and build artefacts in periodic exposure reviews.
  • Give developers a safe, fast process for requesting credentials so they are not tempted to hardcode them.

How external exposure validation helps

Internal code scanning is important, but it may not show every public copy of an organisation’s credentials or every internet-facing asset connected to an incident. An external exposure review can help teams identify publicly accessible repositories and related assets, validate whether a finding creates a real access path, and prioritise remediation based on business impact.

Attack Insights helps organisations understand external exposure and validate security risks. Explore Attack Insights or contact the team to discuss an exposure assessment.

Frequently asked questions

If I delete an API key from a commit, is it safe?

No. The value may remain in repository history or another copy, and someone may already have obtained it. Revoke or rotate the credential first, then remove exposed copies and verify closure.

Should we rewrite Git history after a secret leak?

It depends on the circumstances. Rewriting history can reduce accidental rediscovery, but it does not replace revocation. Assess the repository’s distribution, coordinate with collaborators and follow your incident-response process.

What should we do if we cannot confirm whether a secret is active?

Identify its owner and issuing service, then verify its status through approved administrative controls. If the secret may still grant access and cannot be confirmed safe quickly, escalate and rotate or revoke it according to your incident-response procedures.

Are automated secret scanners enough?

No single scanner finds every secret. Combine scanning with access controls, secure storage, short-lived credentials, developer workflows, log review and a tested response process.

What should be included in a secret-exposure incident record?

Record the secret type without reproducing its value, affected repository and commit, owner, potential permissions, exposure window, revocation time, investigation findings and evidence that remediation was verified.

Sources

Cloud security failures often come from identity, exposure and configuration drift rather than a single software flaw. Use this checklist to review your cloud environment systematically.

AI agents can call tools, access data and take actions on behalf of users. Use these ten controls to limit agent permissions, manage tool risk and monitor autonomous workflows.

Preparing for post-quantum cryptography starts with understanding where cryptography is used. Use these vendor questions to assess dependencies, migration readiness and long-term risk.

External Attack Surface

Discover and monitor every internet-facing asset you own.

Detect new CVEs and exposures as they appear.

Find misconfigurations across AWS, Azure and GCP.

Prove your security controls actually work.

Threat & Digital Risk

Our public threat intelligence platform, in real time.

Spot leaked credentials and targeted threats early.

AI-driven prioritisation that cuts through the noise.

Protect your brand, data and people beyond the perimeter.

API & Email Security

Discover and test externally exposed APIs.

Stop spoofing with SPF, DKIM and DMARC checks.

Dashboards and board-ready security reporting.

Continuously test your public web applications.

Stream validated findings to your SIEM, SOAR and ticketing tools.

Explore

See the full Attack Insights platform.

See Attack Insights in action.