リポジトリの秘密情報漏れと .env チェック
Repo secret leak and .env drift check
作業ツリーと git 履歴から API キー・トークン・秘密鍵・コミットされた .env を探し、値を伏せ字にして「ファイル:行」で報告します。.env.example とコードの環境変数のズレも確認します。
できること
リポジトリを公開する前や外部に渡す前に、秘密情報が紛れ込んでいないかを点検します。
- 作業ツリー(git 管理下のファイルと、無視されていない未追跡ファイル)を走査し、AWS・GitHub・GitLab・Slack・Stripe・OpenAI・Anthropic・Google・SendGrid・npm・PyPI・Hugging Face などのキー形式、秘密鍵ブロック、JWT、接続文字列に埋め込まれたパスワード、
password = "..."のような高エントロピー値を検出 - 結果は「ファイル:行」と伏せ字の値(例:
ghp_******45 (len 40))で表示。秘密の値そのものは出力しません - git 管理されている
.envや、.gitignoreで.envが除外されていないことを指摘 --historyでgit log -p --allの追加行も調べ、過去に一度でもコミットされた秘密や.envを検出.env.exampleとコード(process.env、import.meta.env、os.environ、os.getenv、os.Getenvなど)を突き合わせ、「使っているのに書かれていない変数」「書かれているがコードに見当たらない変数」を一覧化- プレースホルダーらしい値やテスト用フォルダ内の値は重要度を下げて表示
使い方
python scripts/secret_scan.py . --json secret-report.json
python scripts/secret_scan.py . --history --max-commits 500
エージェントは結果を確認し、本物の秘密か、テスト値か、誤検出かを判断したうえで、キーの無効化・再発行を最優先にした対処手順を報告します。重要度 HIGH があると終了コード 1 になるので CI にも使えます。
必要な環境
- Python 3(標準ライブラリのみ)
- 履歴の調査には git
注意点
- 読み取り専用です。ファイルの編集・削除や履歴の書き換えは行いません(書き換えは提案のみ)。
- パターンによる検出なので、誤検出も見逃しもあり得ます。「検出なし」は「既知の形式に一致しなかった」という意味です。
- 一度公開された秘密は、削除しても漏えい済みとして扱い、必ず無効化・再発行してください。
English description
Find API keys, tokens, private keys and committed .env files in the working tree and git history, reported as file:line with masked values, plus .env.example drift.
What it does
Checks a repository for leaked credentials before you publish it or hand it over.
- Scans the working tree (tracked files plus untracked files that are not ignored) for AWS, GitHub, GitLab, Slack, Stripe, OpenAI, Anthropic, Google, SendGrid, npm, PyPI and Hugging Face key formats, private key blocks, JWTs, passwords embedded in connection strings, and high-entropy values in assignments like
password = "..." - Reports
file:linewith a masked value (e.g.ghp_******45 (len 40)); full secret values are never printed - Flags
.envfiles tracked by git and a.gitignorethat does not cover.env --historyalso scans added lines ingit log -p --allto find secrets and.envfiles that were ever committed- Compares
.env.examplewith env vars read in code (process.env,import.meta.env,os.environ,os.getenv,os.Getenvand more): used but undocumented, documented but not found in code - Placeholder-looking values and values under test or fixture folders are shown at lower severity
How to use
python scripts/secret_scan.py . --json secret-report.json
python scripts/secret_scan.py . --history --max-commits 500
The agent verifies each hit (real secret, test value or false positive) and reports remediation with revoking and rotating the key first. Exit code is 1 when a HIGH finding exists, so it also works in CI.
Requirements
- Python 3 (standard library only)
- git for the history scan
Caveats
- Read-only: no edits, deletions or history rewrites (rewrites are only suggested).
- Pattern matching has false positives and false negatives. No findings means no known pattern matched.
- A secret that was ever pushed must be treated as leaked and rotated, even after removal.
インストール方法
- ダウンロードしたZIPを展開します(中に
env-secret-leak-check/フォルダとSKILL.mdがあります)。 - フォルダごと、使うエージェントのスキル置き場にコピーします。
- Claude:
~/.claude/skills/(プロジェクト単位なら.claude/skills/) - Hermes Agent:
~/.hermes/skills/ - Codex:
~/.agents/skills//Cursor:~/.cursor/skills/ - Claude アプリ(claude.ai):「カスタマイズ → スキル」からZIPをアップロード
- Claude:
- エージェントを再起動し、スキル一覧に表示されることを確認します。
出品者
出品スキル 44 件