Course contentsShow
← Security
Lesson 1255 of 3,05225. Application Security - Secure CodingFree lesson

Repository Scanning and History Analysis

Learn to scan entire git history for exposed secrets using tools like TruffleHog and GitGuardian, including archived commits.

Repository Scanning and History Analysis

You'll learn how to scan your entire Git history for exposed secrets, even in commits long since deleted or archived.

Why Git History Matters

When you commit a secret and then remove it in the next commit, you might think it's gone. It's not. Git preserves the entire history of your repository. That API key you accidentally committed three years ago? Still sitting in commit a3f2c91, waiting to be discovered by anyone who clones your repo or gains access to your history.

How History Scanning Works

Tools like TruffleHog and GitGuardian don't just scan your current working directory—they traverse every commit in your repository's history, including:

  • Deleted files
  • Amended commits
  • Rebased branches
  • Archived code
  • Merged pull requests

They use the same regex patterns and entropy detection you learned about in "Secret Patterns and Regular Expressions," but apply them across thousands of historical snapshots.

Basic Scanning Commands

# TruffleHog scans entire git history
trufflehog git https://github.com/yourorg/yourrepo

# Scan local repository including all branches
trufflehog filesystem . --only-verified

These tools create a timeline of exposed secrets, showing when each secret was introduced and whether it still exists in the current code.

Why This Matters

Unlike pre-commit hooks that catch secrets before they're pushed, history scanners find damage already done. They're your archaeological dig through past mistakes—essential for incident response and security audits.

Key Takeaway: Git never forgets—secrets committed at any point in history remain discoverable unless you rewrite history or rotate the credentials, making comprehensive repository scanning essential for finding historical exposure.