SuperAPI AI 工具集

github-sensitive-data-cleanup

安全与审计

查看项目

更新于 10-15 16:20

技能介绍

用途

该技能用于将敏感数据从 Git 仓库历史中安全移除,并把清理后的历史推送到 GitHub。它适用于以下场景:用户要求扫描敏感信息、查看仓库是否泄露;希望清理、净化或重写 Git 历史、从历史中移除密钥;误将密钥、私有域名、内网 IP 或 PII 推送到公开仓库;即将对公开仓库强推(即使不含敏感数据);或提到 git filter-repo、BFG、git-filter-branch 或历史重写。

主要能力

技能捆绑四个脚本,自动化机械性操作:

  • scripts/scan_repo.py:扫描仓库中的密钥与私有上下文。它运行 gitleaks 和一个自定义 bash/grep 层,覆盖 gitleaks 未覆盖的模式(私有域名、内网 IP、中文手机号、某些 PII),并输出 JSON 报告。
  • scripts/rewrite_history.py:创建备份并调用 git-filter-repo 重写历史。它会验证独立仓库、验证 git-filter-repo 已安装,创建 git bundle 备份并用 git bundle verify 校验,运行 git filter-repo --replace-text(不绕过其原生安全检查),在提供 --message-replacements 时还会用 --replace-message 重写提交信息,并报告新旧提交哈希。
  • scripts/verify_cleanup.py:确认敏感内容是否已消失,重新运行扫描并检查任何提交中是否仍残留原始敏感字符串。
  • scripts/safe_push.py:验证仓库可见性并安全推送。它把所选推送 URL 绑定到已保存的仓库目标,校验该目标的可见性和 fork 元数据,仓库为公开且有 fork 时高声警告,检查本地候选提交等于已验证 SHA,以显式 expected-commit lease 执行一次推送,拒绝添加 --no-verify,若 PII Guard 钩子失败则要求修复后重跑。

使用方式

前置工具需按机器安装一次,脚本假定 git-filter-repo 与 gitleaks 在 PATH 上,破坏性操作前会检查:

git-filter-repo (modern replacement for git-filter-branch)

brew install git-filter-repo

gitleaks (secret scanner)

brew install gitleaks

GitHub CLI

brew install gh

工作流为:Step 0 确认仓库路径与当前分支;Step 0.5 绑定每个暴露面(当前文件与托管发布文本、Git 对象与引用、PR 正文编辑历史、缓存视图/PR Git 引用/fork 与克隆);Step 1 扫描敏感数据;Step 1.5 进行 AI 语义审查(第 4 层),因为正则扫描器无法发现真实姓名、项目代号、转录片段、内部会议引用或架构描述等新型私有上下文;Step 2 对发现分类并选择修复方式;Step 3 准备替换文件(git-filter-repo --replace-text 格式,一行一个替换);Step 4 保存发布目标,然后备份并重写;Step 5 验证清理;Step 6 检查可见性并推送;Step 7 推送后验证。

扫描命令示例:

uv run --with gitpython scripts/scan_repo.py --repo /path/to/repo --output /tmp/scan-report.json

启用第 3 层(来自 gitleaks 配置的私有基础设施上下文和可选身份文件):

uv run --with gitpython scripts/scan_repo.py
--repo /path/to/repo
--gitleaks-config ~/scripts/git-pii-guard/gitleaks.toml
--identities-file ~/.config/github-sensitive-data-cleanup/identities.txt
--output /tmp/scan-report.json

重写命令示例:

uv run scripts/rewrite_history.py --repo /path/to/repo
--replacements /tmp/sensitive-replacements.txt
--backup /tmp/repo-backup.bundle
--yes

Entity leaks live in commit MESSAGES too, not just file content. Cover both:

uv run scripts/rewrite_history.py --repo /path/to/repo
--replacements /tmp/sensitive-replacements.txt
--message-replacements /tmp/sensitive-replacements.txt
--backup /tmp/repo-backup.bundle
--yes

验证与推送命令示例:

uv run scripts/verify_cleanup.py --repo /path/to/repo --replacements /tmp/sensitive-replacements.txt

uv run scripts/safe_push.py --repo /path/to/repo --remote origin --branch main
--expected-repository '<saved-host/owner/repo>'
--expected-remote-sha '<saved-full-remote-sha>'
--verified-local-sha '<verified-full-local-sha>'
--yes

适用场景

适用于误推密钥或私有信息后的历史清理、向公开仓库推送前的安全检查、以及任何需要重写 Git 历史的敏感数据整改任务。

限制

该技能设计保守,任何安全检查失败即停止并要求人工确认,而非继续。不可协商的安全规则包括:先扫描再决定,不凭猜测重写历史;重写前用 git bundle 或全新裸克隆备份;推送前用 gh repo view 验证可见性,不从 URL 或目录名推断公开/私有;绝不使用 --no-verify 绕过钩子,PII Guard 钩子失败时修复根因或加白名单;使用绑定到已保存远端提交的单一显式 lease,被拒绝的 lease 即停止推送,绝不回退到 --force 或刷新预期提交;重写后必须验证,干净的 git log 不够,需重跑扫描器并做 AI 语义审查;有 fork 的公开仓库需格外小心,fork 与克隆可能保留旧历史。此外,内置 Git 扫描器不检查托管 PR 修订历史,也不证明已从缓存/fork 中移除。

关于缺失信息:该技能的收费、价格、平台支持范围等未在资料中提供。