Skip to content
Hidden Logic Lab

Review credentials in git history before you call a leak closed

Cursor or Claude Code applies a SKILL.md when a secret touched git: map every commit that contained it, check forks and CI logs, and spell rotation and history rewrite steps — with merge-blocking findings on empty fixes.

Copy prompt

Cursor, Claude Code, GitHub · Coding · 35 min · Working

Outcome

A git-history-secrets SKILL.md in security docs, a PR or incident comment listing reachable commits and remediation order, and no ticket closed after delete-from-head only while blobs still exist in history.

Steps

  1. 1

    Reproduce on a toy leaked fixture

    Commit a dummy key in a throwaway branch, remove it on tip, and run the skill. It should Block closure until history search is documented.

  2. 2

    Pin your history search command

    Add the exact gitleaks or log -S invocation beside the skill. Agents should not improvise a weaker grep each incident.

  3. 3

    Link from secrets-hygiene and CI scan skills

    Prevention skills stop new commits; this one runs after failure. Point AGENTS.md at both paths so responders load the right skill first.

Copy prompt

The prompt to paste

Write SKILL.md for reviewing credentials that landed in git history. Focus on whether the secret is still reachable, who could have cloned it, and the correct remediation sequence — not blame or generic "rotate everything" advice.

Repository context:
[default branch, whether repo is public, fork policy, and approximate contributor count — facts only]
[secret kind: API key, OAuth client secret, private key, database password, signing secret — name the type only]
[detection source: gitleaks, GitHub secret scanning alert, teammate report, CI log grep — how you learned about it]
[whether force-push or history rewrite is allowed on default branch per team policy]

Incident or PR context (paste when using):
[ticket link, files and commits named in the alert, whether the secret was removed in latest main only]

SKILL.md must include:
1. Purpose — removing a key from the tip of main does not revoke a blob that remains in history, tags, or a fork PR branch; agents must map exposure before recommending closure.
2. When to use — any report of a committed secret, failed secret scan, or PR that deletes a key file without history remediation. When not to use — .env.example placeholders with obvious dummy values only.
3. Hard rules for findings:
   - Block: closing incident with only "deleted file on main" when git log or trufflehog/gitleaks still finds the pattern in older commits; recommending rotation without naming every service the key unlocks; force-push plan without notifying collaborators and CI cache consumers; pasting the live secret into chat, PR comment, or SKILL.md appendix for "verification."
   - Warn: secret lived on main longer than one release cycle without scan evidence; same pattern in other repos under the org not yet searched; binary or build artifact commits that may embed the value; submodule or vendored copy with duplicate key; fork existence on public repo before takedown; CI workflow that printed env in logs for that commit range.
   - Note: contributor training, commit message tone — never block on style alone.
4. Review steps the agent must execute:
   - Identify introduction commit and removal commit (if any); list tags and release branches that contain the blob.
   - Run or instruct humans to run history search (git log -S, gitleaks detect --log-opts, or team tool) — output commit shas and paths, not secret values.
   - Check whether GitHub secret scanning, push protection, or gitleaks CI would catch a recurrence; name gaps.
   - Map blast radius: which envs (prod/staging), which third-party dashboards must revoke or rotate, whether JWTs signed with a leaked key need invalidation.
   - If policy allows rewrite: outline git filter-repo or BFG scope (which refs), mandatory collaborator comms, and protected-branch exception process [team placeholder].
   - If rewrite is disallowed: document permanent exposure, accelerated rotation, and monitoring on the vendor key — do not imply history is clean.
   - Search open PRs and default fork branches for the same string pattern (redacted grep patterns only in the comment).
5. PR comment or incident template: timeline table (event — commit/ref — still reachable?), rotation checklist (service — action — owner placeholder), history rewrite yes/no with blockers, merge or closure recommendation.
6. Safe patterns section: never commit secrets; use secret scanning in CI; pre-commit gitleaks; reference env var names in docs; if a key must be tested locally, inject via env not files tracked in git.
7. Two example prompts: accidental .env committed for one commit vs private key in README for six months on a public repo.
8. Pitfalls: assuming GitHub "removed secret" UI means history is gone, rotating only the leaked key while paired refresh tokens remain valid, rewriting history without invalidating deploy keys still checked out on runners, searching only main and not tags.
9. Done means: every Block resolved, reachable commit list attached (shas only), rotation owners named or marked [assign], rewrite decision explicit, no live secret material in any artifact from this review.

Rules:
- Never reproduce detected secret strings; describe length and prefix class only (e.g. sk-… OpenAI-shaped) if needed for scope.
- Do not run git filter-repo or force-push — the skill plans; humans execute.
- Output only SKILL.md markdown.

Secret scanning alerts on public repos may mean the key was scraped before you rotated. The skill must treat external exposure as unresolved until the vendor confirms revocation and you have commit-level reachability data.

Sample case written by Hidden Logic Lab. Not affiliated with Cursor or Claude Code or GitHub.

Get new cases in your inbox

Weekly notes on new use cases and agent workflows. No product pitches.

Occasional notes on new cases. No product pitches in the first note.