Git Security Guard — 敏感信息泄露防护

SkillFiles & storage

Git security guard. Prevents sensitive information such as API keys, tokens, private keys, wallet addresses, and .env files from being committed to Git. Automatically triggers on git commit, git push, creating a new repo, or PR review. Also triggers when the user says "commit", "push", "安全检查", "secu

Instructions available. Your AI can read the instructions. Execution depends on the setup they require.

Add ahel to your AI once: Claude, ChatGPT, Cursor, Claude Code or Codex. Then ask it to use this.

Then ask your AI: use the Git Security Guard skill

What this skill tells your AI

The instructions your AI receives, as published by myths-labs/muse in skills/toolkit/git-security-guard/SKILL.md and read by ahel’s review.

触发时机

  • 每次 git commit 前(自动)
  • 每次 git push 前(自动)
  • 新项目/新 repo 初始化时
  • 用户要求安全检查时

Pre-Commit 检查清单

Step 1: 检查暂存文件名

git diff --cached --name-only | grep -iE '\.env|\.pem|\.p12|\.jks|\.key$|\.muse/|\.agent/|\.gemini/|memory/|convo/'

任何匹配 → 立即阻止 commit,报告给用户。

Step 2: 检查暂存内容中的 Key 模式

git diff --cached | grep -iE 'sk-[a-zA-Z0-9]{20}|AIzaSy[a-zA-Z0-9_-]{33}|gsk_[a-zA-Z0-9]{20}|sk_live_|sk_test_[a-zA-Z0-9]{20}|pk_live_|pk_test_[a-zA-Z0-9]{20}|eyJhbGci[a-zA-Z0-9_-]{50}|-----BEGIN.*(PRIVATE|RSA)|AKIA[0-9A-Z]{16}|ghp_[a-zA-Z0-9]{36}|whsec_|xoxb-|xoxp-|service_role'

任何匹配 → 立即阻止 commit,报告给用户。

Step 3: 排除误报

以下不算泄露:

  • .env.example 中的占位符(your-api-key、sk_test_your-...)
  • process.env.XXX 引用(代码读环境变量,不是硬编码)
  • node_modules/ 中的加密库代码
  • 公开合约地址(USDC/USDT 等已知合约)
  • 文档中的"不要这样做"示例

禁止提交的文件模式

文件模式原因
.env.local / .env.prod* / .env.vercel*含真实 API Key
.muse/ 目录含内部战略/开发状态
.agent/ 目录含内部 Skill/Prompt
.gemini/ 目录含 AI 对话记录
memory/ / convo/对话/记忆文件
*.pem / *.p12 / *.jks / *.key私钥/证书

禁止出现在代码中的 Key 模式

模式服务
sk-[a-zA-Z0-9]{20,}OpenAI
AIzaSy[a-zA-Z0-9_-]{33}Google/Gemini
gsk_[a-zA-Z0-9]{20,}Groq
sk_live_ / sk_test_[实际值]Stripe Secret
pk_live_ / pk_test_[实际值]Stripe Publishable
eyJhbGci[长JWT]JWT Token (Supabase/Vercel)
AKIA[0-9A-Z]{16}AWS
ghp_[a-zA-Z0-9]{36}GitHub PAT
-----BEGIN (RSA )?PRIVATE KEY私钥
0x[a-fA-F0-9]{64}钱包私钥(注意:40位是地址,64位才是私钥)
whsec_Stripe Webhook Secret
xoxb- / xoxp-Slack Token

新项目 .gitignore 模板

新 repo 第一个 commit 前必须包含:

# Env files (NEVER commit real keys)
.env
.env.local
.env.*.local
.env.prod*
.env.vercel*

# Internal files
.muse/
.agent/
.gemini/
memory/
convo/

# Private keys
*.pem
*.p12
*.jks
*.key

# IDE
.idea/
.vscode/

# OS
.DS_Store

泄露应急处理

如果发现敏感信息已经被 commit(即使还没 push):

1. 从全部历史中清除

git stash --include-untracked
FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch --force --index-filter \
  'git rm --cached --ignore-unmatch [泄露的文件]' --prune-empty HEAD

2. 清除本地残留

git for-each-ref --format='%(refname)' refs/original/ | xargs -n1 git update-ref -d
git reflog expire --expire=now --all
git gc --prune=now --aggressive

3. Force push(如果已推远程)

git push origin main --force

4. 轮换所有泄露的 Key

  • 去对应平台重新生成 Key
  • 更新 Vercel/服务器环境变量
  • 更新本地 .env.local

Deep Scan(完整历史扫描)

用于定期安全审计或怀疑有泄露时:

git log --all -p | grep -inE 'sk-[a-zA-Z0-9]{20}|AIzaSy|gsk_|sk_live|sk_test_[a-zA-Z0-9]{20}|pk_test_[a-zA-Z0-9]{20}|eyJhbGci[a-zA-Z0-9_-]{50}|-----BEGIN.*PRIVATE|AKIA[0-9A-Z]{16}|0x[a-fA-F0-9]{64}' | grep -v node_modules | head -30

Signals

GitHub stars
35
Forks
4
Last commit
Sep 2026
Advanced
Item type
skill
Key
git-security-guard
Source
github.com/myths-labs/muse