---
title: "Scan the whole history for secrets · Agent Wranglers"
url: https://agentwranglers.se/playbook/due-diligence/code-and-ownership/history-secret-scan
id: TDD-7
level: Required
risk: takeover
updated: 2026-10-27
build: a2a6bdfed830
tokens: 879
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Scan the whole history for secrets

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Code and ownership](https://agentwranglers.se/playbook/due-diligence/code-and-ownership.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: TDD-7
- Level: Required
- Chapter: [Code and ownership](https://agentwranglers.se/playbook/due-diligence/code-and-ownership.md)
- Rule: Run a secret scanner over every commit and branch of the repository, and test which found secrets still work. Every working secret is revoked before closing.
- Check: The scan report covers every branch and every commit, and lists 0 verified live secrets, or each live secret has a revocation date before closing.
- Risk: An account or system taken over
- How: A key deleted from the code years ago is still in the history, and anyone with a copy can use it. A scanner that verifies keys against their service, such as TruffleHog, separates live keys from dead ones. Scan forks, archived repositories and the builder's export too. The ongoing rule is [Keep secrets out of code](https://agentwranglers.se/playbook/application-security/secrets-and-configuration/secrets-out-of-code.md), with a scanner from [Use TruffleHog to find leaked secrets](https://agentwranglers.se/playbook/stack/testing-and-code-quality/secret-scanner.md).

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### Shell example

```sh
trufflehog git file://. --results=verified --fail
gitleaks git --log-opts="--all" --report-path gitleaks.json
```

## Sources

- [GitHub on secret scanning](https://docs.github.com/en/code-security/secret-scanning/introduction/about-secret-scanning)
- [GitHub on removing sensitive data](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/removing-sensitive-data-from-a-repository)
- [OWASP Secrets Management Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html)

## Related rules

- STK-50 [Use TruffleHog to find leaked secrets](https://agentwranglers.se/playbook/stack/testing-and-code-quality/secret-scanner.md) in Software choices
- TKO-2 [Rotate every secret the previous team could read](https://agentwranglers.se/playbook/codebase-takeover/triage/rotate-inherited-secrets.md) in Codebase takeover
- APS-60 [Keep secrets out of code](https://agentwranglers.se/playbook/application-security/secrets-and-configuration/secrets-out-of-code.md) in Application security

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/due-diligence/code-and-ownership/history-secret-scan">Agent Wranglers technical due diligence playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [List the licences of the code and every dependency](https://agentwranglers.se/playbook/due-diligence/code-and-ownership/licence-inventory.md)
- Next: [Find every part that depends on one person or one tool](https://agentwranglers.se/playbook/due-diligence/code-and-ownership/single-points-of-failure.md)
- [Code and ownership](https://agentwranglers.se/playbook/due-diligence/code-and-ownership.md)
