Skip to content

skillSecurity

Secrets Scanning Cleanup

Finds API keys and passwords committed to a repository, plans their rotation, removes them from history and adds a check against repeats.

npx workspacetemplates add secrets-scanning-cleanup --tool claude-code

Writes 1 file to .claude/skills/secrets-scanning-cleanup/

.claude/skills/secrets-scanning-cleanup/SKILL.md27 lines · 1.7 KBFile
---
name: secrets-scanning-cleanup
description: Finds API keys and passwords committed to a repository, plans their rotation, removes them from history and adds a check against repeats.
---

# Secrets scanning cleanup

Treat every secret you find as already compromised. Rotation comes before cleanup.

## Steps

1. Scan the working tree and history. Use gitleaks or trufflehog if installed (`gitleaks detect --redact`); otherwise search with patterns for `AKIA`, `ghp_`, `sk_live_`, private key headers, and assignments like `password=` in config files.
2. Triage each hit: real credential, test value, or example. Record file, commit, and the service it belongs to. Mask values to the first four characters in every message you write.
3. Produce a rotation list for the user: which provider console, which key, what depends on it. Do not rotate anything yourself. Wait for confirmation that each key is revoked.
4. Move the value out of code: read it from an environment variable or secret manager, add the file to `.gitignore`, and commit a `.env.example` with empty names.
5. Only after rotation, offer a history rewrite with `git filter-repo --replace-text`. Explain it changes commit hashes and forces every collaborator to re-clone. Ask before running it, and never force-push without a yes.
6. Prevent repeats: add a gitleaks pre-commit hook and a CI step that fails on new findings.

## Rules

- Never paste a full secret into chat, logs or a commit message.
- Deleting the file in a new commit is not a fix.
- Check for the same secret in CI variables, Docker images and build logs.

## Report

Findings table (masked), rotation checklist with status, what changed in the repo, and the guard added.

What it does

A leaked key is only fixed when it is revoked. Deleting the line in a new commit leaves the secret in history, in forks and in every clone. This skill puts the steps in the right order: find, rotate, then clean history, then prevent.

It never prints a full secret in its output, and it asks before any rewrite of shared history. The last step adds a pre-commit and CI scan so the same mistake is caught next time.

Example

you › GitHub emailed us that a Stripe key is in our repo. Clean it up.

agent › Found sk_li... in config/payments.js since commit 3f9a2c1, plus a second key in an old .env.bak. Rotation list: Stripe dashboard, roll both keys, update the deploy variable. Code now reads STRIPE_KEY from the environment and .env.bak is ignored. History rewrite is ready but waiting for your yes. Added gitleaks to pre-commit and the CI workflow.

Questions

Why rotate before rewriting history?
Anyone who cloned or forked the repo already has the secret, and automated scrapers find leaks within minutes. Only revoking the key makes it useless.
Does it rewrite history on its own?
No. Rewriting changes every hash after the leak, so it stops and asks, and it never force-pushes without your explicit approval.
  • CSRF and CORS Hardening

    SkillSecurity

    Free