Skip to content

Secret Scanning

m4bwav edited this page Nov 21, 2026 · 1 revision

Two engines

sw.py repo PATH uses gitleaks when it is on the PATH (gitleaks git PATH --redact), and reports each finding with REDACTED in place of the match. Without gitleaks, or when its output cannot be parsed, it falls back to the built-in rules and says engine: builtin. The built-in rules are a floor, not full coverage; the output says so on every run.

The built-in engine reads git log -p --all --unified=0 and looks only at added lines, so a secret that a later commit removed is still found, and a removed line is not reported again.

Built-in rules

Rule Matches
github-token ghp_, gho_, ghu_, ghs_, ghr_ tokens and github_pat_ fine-grained tokens
aws-access-key access key IDs starting AKIA or ASIA
openai-key sk- and sk-proj- keys
anthropic-key sk-ant- keys
google-api-key AIza keys
slack-token xoxb-, xoxa-, xoxp-, xoxr-, xoxs-
stripe-key sk_live_ and rk_live_
npm-token npm_ tokens
private-key -----BEGIN ... PRIVATE KEY----- headers (RSA, EC, OPENSSH, DSA, PGP)
generic-assignment a name containing password, passwd, secret, api key or token, then = or :, then a quoted value of 12 or more characters

One value can match two rules, as the GitHub token on Commands does.

generic-assignment in 0.1.1

In 0.1.0 the keyword had to be a whole word, so AWS_SECRET_ACCESS_KEY = "..." and db_password: '...' were missed. A repository whose only commit adds an AWS secret key to .env, scanned by 0.1.0:

engine: builtin  findings: 0
note: built-in rules are a floor; install gitleaks (winget install gitleaks) for full coverage

The same repository scanned by 0.1.1, exit code 1:

engine: builtin  findings: 1
  generic-assignment     36ab1d37341d .env wJal******CY
note: built-in rules are a floor; install gitleaks (winget install gitleaks) for full coverage

From 0.1.1 the keyword may sit inside a longer name, the keyword list adds pwd, access_key, private_key, auth_key and credential, the name may be quoted ("apiKey": "...") and => and := count as assignments. Short values and unquoted ones (token = os.environ['X']) are still ignored.

Masking

A match longer than 8 characters prints its first 4 and last 2 characters around six asterisks (ghp_******e5); shorter ones print ****. Private key headers print as they are, since the header holds no secret.

Workflow checks

repo also reads .github/workflows/*.yml in the working tree and adds findings named workflow:...:

  • workflow:unpinned-action: a uses: line whose ref is not a 40-character commit SHA (local ./ actions and docker:// are skipped)
  • workflow:write-all-permissions: permissions: write-all
  • workflow:pull_request_target: the trigger that runs fork pull requests with repository secrets

After a finding

Rotate the secret at its issuer first; that is the fix. Scrubbing history is cleanup, and forks and clones keep their copy. The steps, in order: Incident playbooks.

Clone this wiki locally