SuperAPI AI 工具集

security-ownership-map

安全与审计

查看项目

更新于 10-15 20:21

技能介绍

Security Ownership Map 面向需要评估代码安全归属风险的团队,基于 git 提交历史构建人员与文件的二分图,并输出可查询、可导入图数据库的结果。

用途: 从 git 仓库历史中分析“谁拥有哪些代码”,识别敏感代码的所有权集中与失守风险,包括巴士因子、孤立敏感代码、隐藏所有者等。

主要能力:

  1. 构建人员—文件归属图,统计触达关系(touches);
  2. 计算巴士因子(bus factor)并定位低巴士因子的敏感热点;
  3. 依据可配置的敏感规则(默认覆盖常见 auth/crypto/secret 路径,也可用 CSV 自定义 pattern、tag、weight);
  4. 构建文件共变图,基于共享提交的 Jaccard 相似度对文件聚类,默认忽略锁文件、.github/*、编辑器配置等“胶水”文件,并默认排除 Dependabot 提交,可用参数覆盖;
  5. 默认启用社区检测,输出每个社区的维护者;
  6. 导出 CSV/JSON,支持导入 Neo4j 或用于 Gephi 可视化;可选输出 GraphML;
  7. 提供查询脚本按有界 JSON 切片返回结果,便于在 LLM 上下文中使用而不加载全图;
  8. people.csv 基于作者提交时区偏移检测主时区。

使用方式: 环境要求 Python 3 与 networkx,安装命令:pip install networkx 在仓库根目录运行主脚本(示例): python skills/skills/security-ownership-map/scripts/run_ownership_map.py
--repo .
--out ownership-map-out
--since "12 months ago"
--emit-commits 默认排除合并提交,默认使用作者身份与作者日期;可用 --identity committer、--date-field committer、--include-merges 调整。可用 --since/--until 限定时间窗口,用 --no-communities 关闭社区检测,用 --graphml 输出 GraphML,用 --no-cochange 关闭共变图。

敏感规则可通过 CSV 文件自定义,例如:

pattern,tag,weight

/auth/,auth,1.0 /crypto/,crypto,1.0 **/*.pem,secrets,1.0 然后使用 --sensitive-config path/to/sensitive.csv。

输出产物包括 people.csv、files.csv、edges.csv、cochange_edges.csv、summary.json、可选的 commits.jsonl、communities.json、cochange.graph.json(或 ownership.graph.json)、可选的 ownership.graphml/cochange.graphml。

查询脚本示例: python skills/skills/security-ownership-map/scripts/query_ownership.py --data-dir ownership-map-out people --limit 10 python skills/skills/security-ownership-map/scripts/query_ownership.py --data-dir ownership-map-out files --tag auth --bus-factor-max 1 python skills/skills/security-ownership-map/scripts/query_ownership.py --data-dir ownership-map-out summary --section orphaned_sensitive_code

适用场景: 安全审计前的所有权梳理;识别敏感代码的低巴士因子热点与陈旧、无人维护的敏感代码;发现隐藏的敏感代码所有者;对比 CODEOWNERS 以发现归属漂移;为图数据库构建可查询的代码归属拓扑。

限制与注意事项: 需要 Python 3 与 networkx;分析基于 git 提交历史,依赖仓库历史完整性;大仓库建议用 --since/--until 缩小范围;默认排除合并提交、Dependabot 提交与“胶水”文件,可通过参数覆盖;touches 默认按一次提交计一次(可用 --touch-mode file 改为按文件计数);可用 --window-days、--weight recency --half-life-days 平滑变更波动;可用 --ignore-author-regex 过滤机器人;可用 --min-share 仅显示稳定维护者。关于收费、价格、支持平台等信息暂未提供。