Secrets scan
Goal
Find real credentials that are exposed, and make sure the next one is caught before it lands.
A good result separates live secrets from placeholders and states clearly which ones must be rotated.
When to use
- A repository is about to be made public or shared.
- The user suspects a key was pushed.
- The team wants automated secret detection.
- For the rotation steps after a leak, use
use_skillwithapi-key-rotation.
Steps
- Check for an installed scanner with
run_command, such asgitleaks versionortrufflehog --version. If one exists, run it on the working tree and on history. - Without a scanner, search the tree with
rgusing patterns:BEGIN (RSA|EC|OPENSSH|PRIVATE) KEY,AKIA[0-9A-Z]{16},xox[baprs]-,ghp_,sk_live_,password\s*=,://[^/\s:]+:[^@\s]+@. - List config-like files with
ls:.env*,*.pem,*.key,credentials.json,terraform.tfvars,*.p12, and check each is ignored by.gitignore. - Search history for removed files and values:
git log --all --diff-filter=D --name-onlyandgit log -p -S"<pattern>"throughrun_command. - Classify every hit: live secret, example or placeholder, test fixture, public identifier (a publishable key is not secret). Check the key prefix meaning in the provider docs with
read_urlwhen unsure. - For live secrets, do not print the full value in your answer. Show the file, line and the first four characters.
- Tell the user to rotate every live secret now. Removing it from the code does not undo exposure, because history, forks and caches keep it.
- Replace the literals with environment variable reads using
edit_file, and add the names to.env.examplewith placeholders. - Add
.gitignoreentries for secret files. - Add prevention: a pre-commit hook or CI step with the chosen scanner, and a baseline file for known false positives. Create the config with
create_file. - If history rewrite is wanted, explain the cost (all clones need resync) and that rotation still comes first.
- Rerun the scan and confirm the live findings are gone.
Gotchas
- Rewriting git history without rotating the key leaves the secret valid. It may already be copied by bots that watch public pushes.
- High entropy strings include hashes, ids and build outputs. Expect false positives and review each.
- Secrets also hide in Docker images, CI logs, issue comments, notebooks and compiled front-end bundles.
- A
.envadded to.gitignoreafter being committed is still tracked. Rungit rm --cachedfor it. - Base64 encoding hides nothing from a scanner that decodes, and nothing from an attacker.
- Never paste found secrets into chat, tickets or search engines when testing whether they work.
Output
- Findings table: file, line, type, status (live, placeholder, fixture), action.
- Which secrets must be rotated, listed first.
- Prevention added and the clean rescan result.
