---
name: secrets-audit
description: Find committed credentials, API keys, and tokens in a repository, including in git history, and handle them correctly once found. Use before making a repository public, when preparing a release, when onboarding an unfamiliar codebase, or whenever the user asks about leaked secrets, hardcoded credentials, or scrubbing git history.
title: secrets-audit
canonical_url: https://skilld.dev/gh/catidegla/skillbelt/secrets-audit
last_updated: 2026-09-22T23:31:57.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install catidegla/skillbelt/secrets-audit`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/secrets-audit`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/catidegla/skillbelt/secrets-audit) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/secrets-audit`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/secrets-audit --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/secrets-audit --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Secrets audit

Two jobs that get confused with each other. Finding a secret in the working tree is easy. Getting it out of git history, and understanding that finding it means it is already burned, is the part people get wrong.

**A committed secret is a compromised secret.** Rotation comes first. History rewriting is cleanup, not remediation. If the repository was ever public, ever cloned, or ever pushed to a service that indexes code, assume the value is known.

## Scan the working tree

High-confidence patterns, low false-positive rate:

```bash
rg -n --glob '!node_modules' --glob '!vendor' --glob '!*.lock' \
  -e 'AKIA[0-9A-Z]{16}' \
  -e 'ASIA[0-9A-Z]{16}' \
  -e 'gh[pousr]_[A-Za-z0-9]{36,}' \
  -e 'github_pat_[A-Za-z0-9_]{22,}' \
  -e 'sk_live_[A-Za-z0-9]{20,}' \
  -e 'rk_live_[A-Za-z0-9]{20,}' \
  -e 'xox[baprs]-[A-Za-z0-9-]{10,}' \
  -e 'sk-ant-[A-Za-z0-9_-]{20,}' \
  -e 'sk-proj-[A-Za-z0-9_-]{20,}' \
  -e 'AIza[0-9A-Za-z_-]{35}' \
  -e 'SG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43}' \
  -e '-----BEGIN [A-Z ]*PRIVATE KEY-----'
```

Connection strings, which carry credentials inline and are missed by keyword scans:

```bash
rg -n --glob '!node_modules' --glob '!vendor' \
  -e '(postgres|postgresql|mysql|mongodb(\+srv)?|redis|amqp)://[^:@\s/]+:[^@\s]+@'
```

Assignment-shaped matches. Noisier, so read every hit:

```bash
rg -n -i --glob '!node_modules' --glob '!vendor' --glob '!*.lock' \
  '\b(api[_-]?key|secret|passwd|password|token|credential|private[_-]?key)\b\s*[:=]\s*["'"'"'][^"'"'"'\$\{]{12,}["'"'"']'
```

The `[^"\$\{]` part excludes `env('KEY')`, `${VAR}` and `process.env.X`, which is most of the noise.

Files that should not be tracked at all:

```bash
git ls-files | rg -i '(\.env($|\.)|\.pem$|\.p12$|\.pfx$|\.keystore$|id_rsa|\.ppk$|credentials(\.json)?$|service-account.*\.json$)'
```

## Scan git history

The working tree being clean means nothing. Check every blob that ever existed:

```bash
# Every version of a path that looks sensitive.
git log --all --full-history --oneline -- '*.env' '*.pem' '*credentials*' '*secret*'

# Search the content of all commits.
git rev-list --all | while read -r commit; do
  git grep -I -n -e 'AKIA[0-9A-Z]\{16\}' -e 'sk_live_' -e 'gh[pousr]_' "$commit" 2>/dev/null
done | head -50
```

That loop is slow on large repositories. `gitleaks detect --no-git=false` and `trufflehog git file://.` do the same job faster and verify some key types against the provider, which removes false positives. Use them when available.

## Triage each hit

For every candidate, answer three questions before acting:

1. **Is it real, or a placeholder?** `sk_test_`, `example`, `changeme`, `xxx`, and obvious dummy values in fixtures are not incidents. Test keys for payment providers are usually safe by design, but confirm the prefix rather than assuming.
2. **Is it live?** A rotated key in history is already handled. Check the provider dashboard for last-used timestamps.
3. **What does it reach?** A read-only analytics key and a production database password need different responses.

## Remediation, in order

**1. Rotate.** Always first, always before touching history. Revoke the old credential at the provider. If the secret is a database password, rotate it and check for connections still using the old one.

**2. Check for use.** Provider audit logs will show whether the key was used from an address you do not recognize. AWS CloudTrail, GitHub audit log, Stripe events.

**3. Remove from the working tree.** Move the value to environment configuration, add the file to `.gitignore`, commit.

**4. Rewrite history, if it is worth it.** For a private repository with a rotated key, this is often optional and disruptive. For a repository about to go public, do it.

```bash
# git-filter-repo is the maintained tool. filter-branch is deprecated.
pip install git-filter-repo

git filter-repo --path .env --invert-paths
# or replace the literal value everywhere it appears
echo 'literal:AKIAIOSFODNN7EXAMPLE==>REMOVED' > replacements.txt
git filter-repo --replace-text replacements.txt

git push --force --all
git push --force --tags
```

Rewriting changes every commit hash after the touched commit. Every collaborator must re-clone, and open pull requests will need rebasing. Say so before doing it.

**5. Ask the host to purge caches.** GitHub keeps unreferenced objects reachable through the API for a while, and forks keep their own copies. Contact support to have cached views of the old commits removed. Forks are not rewritten by your force push, so check whether any exist.

## Prevent recurrence

- `.gitignore` covering `.env`, `.env.*`, `*.pem`, `*.p12`, `credentials.json`, and any local override file the framework uses. Keep `.env.example` tracked with empty values.
- Enable the host's secret scanning and push protection. On GitHub this is free for public repositories and blocks the push rather than reporting after the fact.
- A pre-commit hook running `gitleaks protect --staged`.
- Move real values into a secret manager rather than developer machines.

## Reporting

For each confirmed secret give: the file and line or the commit hash, the type of credential, what it grants access to, whether it appears in history, and whether it has been rotated yet. Lead with anything still live.

State plainly when the working tree is clean but history is not. That distinction decides whether the repository can safely be made public.
