agentleFS
bokuwalilybokuwalily/claude-code-skills/skills/git-prepush-secret-remote-check/SKILL.md

git-prepush-secret-remote-check

Skill0 starsChanged 5 months agoMITView on GitHub

git pushやパブリック公開の直前に実行する。リモートURLが自分のリポジトリを指しているか確認し、ステージ・差分内のAPIキー/トークン/PII漏洩をスキャンする。複数セッションで「サードパーティforkへのwrong-remote」と「PII流出」が実際に発生したことへの対策。

  • Reads credentials
  • Commits and pushes

1 other project uses a version of this, 1 of them edited.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

Procedure

1. リモートURLを確認する

git remote -v

出力例:

origin  git@github.com:YOUR_USERNAME/YOUR_REPO.git (fetch)
origin  git@github.com:YOUR_USERNAME/YOUR_REPO.git (push)

自分のアカウント名が含まれていることを確認。サードパーティのfork元URLになっていれば即修正:

git remote set-url origin git@github.com:YOUR_USERNAME/YOUR_REPO.git

2. ステージ済みファイルに秘密情報がないかスキャン

git diff --cached | grep -iE \
  "(api_?key|secret|token|password|passwd|auth|credential|access_?key|private_?key)\s*[=:]\s*\S+"

何も出力されなければOK。ヒットしたら即 git reset HEAD <file> でアンステージし、.env 化してから .gitignore に追加。

3. コミット済み履歴を含むスキャン(念のため)

git log --oneline -10
git show HEAD | grep -iE "(api_?key|secret|token|password)\s*[=:]\s*\S+"

4. .env 系ファイルが追跡されていないか確認

git ls-files | grep -E "^\.env"

出力があればトラッキングから除外:

git rm --cached .env
echo ".env" >> .gitignore
git add .gitignore

5. 個人情報(PII)の簡易チェック

git diff --cached | grep -iE \
  "(\b[0-9]{3}-[0-9]{4}-[0-9]{4}\b|@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})"

電話番号・メールアドレスパターンにヒットしたらコード内のハードコーディングを確認。


Pitfalls

  • fork元リモートのままpush:テンプレートをforkしたまま origin を変えずにpushすると、サードパーティリポジトリに自分のコードが公開される。手順1を必ず行う。
  • .env ファイルの誤コミット:create-next-app や vite はデフォルトで .env.local を .gitignore に入れるが、自前設定のプロジェクトでは漏れる。手順4で確認。
  • grep のパターンは完璧ではない:難読化・Base64化された秘密情報は検出できない。gitleaks や truffleHog などの専用ツールが使える環境ならそちらを優先。
  • force-pushで履歴書き換えても残る:一度でも公開リポジトリにpushしたシークレットはGitHub側にキャッシュされる可能性がある。露出したら即ローテーション。

Verification

# リモートが自分のリポジトリを指していること
git remote -v | grep "YOUR_USERNAME"

# シークレットスキャンで何もヒットしないこと
git diff --cached | grep -iE "(api_?key|secret|token|password)\s*[=:]\s*\S+" | wc -l
# → 0 であればOK

# .env系が追跡されていないこと
git ls-files | grep -E "^\.env" | wc -l
# → 0 であればOK

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.