Skip to content
back to the map
testing technique
stage: source
2 min read

Secrets Scanning

Hunts tokens, API keys and passwords before they become an incident, including in git history.

GitleaksTruffleHogGitHub Secret Scanning

What it is

sweeps code, commits, pull requests and configuration files looking for credentials: API keys, access tokens, passwords, private keys and connection strings.

It is the cheapest check in the pipeline and protects against one of the most common leaks: a credential committed by mistake.

How it works: patterns and entropy

The first layer is pattern matching: token formats are recognizable. AWS keys start with AKIA, Stripe API tokens with sk_live_, private keys with -----BEGIN. A well-made regex catches most of them.

The second layer is entropy analysis, for formats nobody documented: strings that look highly random (many distinct characters, no word pattern) near suspicious names like api_key, secret or password. It is what catches homegrown internal service keys.

The third layer, when available, is active verification: the tool tests whether the credential found is valid, turning a 'potential finding' into a 'confirmed incident'.

A leak, from commit to rotation

The classic scenario in three acts. Act one: someone pastes a production key straight into the code. It works, the test passes, life goes on.

src/payments.tstypescript
const stripe = new Stripe("sk_live_51H8xQ2eZvKYlo2CxT9mPq3");
                              // production key in the code

Act two: the bot already found it

Seconds after the push, automated third-party scrapers (and GitHub's own secret scanning) are already testing the key. Deleting the commit does not fix it: the secret remains in git history, in forks and in caches. A typical local scanner report:

gitleaks reporttext
Finding:  stripe-access-token
Secret:   sk_live_51H8xQ2eZ...
File:     src/payments.ts:1
Commit:   a1b2c3d
Entropy:  4.71

Act three: revoke first, explain later

The only correct response is to revoke and rotate the credential immediately, before cleaning the repository and before discussing process. No history cleanup is fast enough to compete with a bot that tests the key every second.

The structural prevention is to take secrets out of the code for good: managers like HashiCorp Vault, AWS Secrets Manager or Doppler inject the credential at runtime and allow rotation without a deploy.

Secrets scanningScanning for exposed credentials in code, commits and git history.see in glossary →

connections on the map

  • Secrets Scanningstage: sourceCI/CD

updated on 14/10/2026 · sources to go deeper · report an error

in other domains

Study before

Unlocks

test what you learned

Loading questions…