badchars/github-security-mcp

GitHub: badchars/github-security-mcp

面向 AI 代理的 GitHub 安全态势分析工具,通过 MCP 协议提供 39 个工具和 45 项检查,覆盖组织、仓库、Actions、secrets、供应链和访问控制六大领域的安全审计。

Stars: 0 | Forks: 0


github-security-mcp

面向 AI 代理的 GitHub 安全态势分析。

GitHub Enterprise 安全功能的费用为 $21/用户/月。
这为您的 AI 代理提供了 免费的同等可见性 —— 包括组织、仓库、Actions、secrets、供应链。


问题背景独特之处快速开始AI 能力工具检查项架构

License Bun MCP 39 Tools 45 Checks 6 Categories

## 问题背景 GitHub 安全功能是碎片化的。针对组织设置、仓库配置、Actions 工作流分析、secret 扫描、供应链和访问控制,您需要使用各自独立的工具。没有单一工具能涵盖所有内容,而且没有一种工具能与 AI 代理协同工作。 ``` Traditional workflow: manually check org settings → click through 15 pages run github-advisory-db for each repo → one at a time grep workflows for script injection → miss half the patterns review collaborator access → spreadsheet hell check secret scanning alerts → another dashboard ────────────────────────────────────────── Total: hours of manual work per org ``` **github-security-mcp** 通过 [Model Context Protocol](https://modelcontextprotocol.io) 为您的 AI 代理提供 39 个工具和 45 项安全检查。代理直接调用 GitHub API,理解其发现的内容,并准确告诉您需要修复什么。 ``` With github-security-mcp: You: "Audit my GitHub org for security issues and prioritize the fixes" Agent: → checks org settings (2FA, SSO, member privileges) → scans repos (branch protection, secret scanning, Dependabot) → analyzes workflows (script injection, unpinned actions, OIDC) → reviews access (teams, collaborators, PATs, GitHub Apps) → "12 critical, 8 high — here are the top 5 to fix now" ``` ## 独特之处 现有工具仅关注 GitHub 安全的某一个切片。github-security-mcp 覆盖完整的技术栈,并可与任何 AI 代理配合使用。
现有工具 github-security-mcp
接口 CLI / GitHub UI / 仪表盘 MCP — AI 代理实时调用工具
范围 单一领域 (Actions, 或 secrets, 或仓库) 全栈: 组织 + 仓库 + Actions + secrets + 供应链 + 访问控制
关联分析 无 — 孤立的发现结果 代理链式推理: "此未固定的 action + 写入权限 + 无环境保护 = 供应链风险"
修复建议 通用文档链接 代理针对您的具体配置生成特定的修复指南
Actions 分析 大多数工具跳过工作流 8 项检查: 脚本注入、PR target、OIDC、版本固定、secrets、runners、环境、权限
Enterprise 功能 需要 GitHub Enterprise ($21/用户/月) 免费 — 使用公开 API,并对 Enterprise 专属功能进行优雅降级

与热门工具的具体对比
| 工具 | 功能 | 局限性 | |---|---|---| | [Allstar](https://github.com/ossf/allstar) | 通过 GitHub App 强制执行仓库设置 | 无 Actions 分析,无 secret 扫描,无访问审计 | | [Scorecard](https://github.com/ossf/scorecard) | 仓库的 OpenSSF 安全评分 | 聚焦单仓库,无组织级检查,无实时交互 | | [Legitify](https://github.com/Legit-Labs/legitify) | 组织 + 仓库策略强制执行 | CLI 输出,无 AI 集成,Actions 分析有限 | | [step-security/harden-runner](https://github.com/step-security/harden-runner) | 运行时 Actions 安全 | 仅限 Actions,无组织/仓库/访问检查 | | [GitGuardian](https://www.gitguardian.com/) | 提交中的 Secret 检测 | 仅 SaaS,无自托管,仅限于 secrets 领域 | | [Socket](https://socket.dev/) | 供应链风险分析 | 聚焦包管理,无组织/Actions/访问分析 | 所有这些都是优秀的工具。github-security-mcp 并不取代它们 — 它填补了为 AI 代理提供跨所有 GitHub 安全领域的**统一、交互式访问**的空白。
## 快速开始 ### 安装 ``` git clone https://github.com/badchars/github-security-mcp.git cd github-security-mcp bun install ``` ### 设置认证 ``` # Classic PAT (需要: repo, admin:org, admin:org_hook, admin:repo_hook) export GITHUB_TOKEN=ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # Fine-grained PAT (首选 — 最小权限) # Organization: Members (读取), Administration (读取) # Repository: Administration, Code scanning, Dependabot, Secret scanning, # Actions, Environments, Webhooks (均为只读) ``` ### 连接到您的 AI 代理
Claude Code ``` claude mcp add github-security -- bun run /path/to/github-security-mcp/src/index.ts ```
Claude Desktop 添加到 `~/Library/Application Support/Claude/claude_desktop_config.json`: ``` { "mcpServers": { "github-security": { "command": "bun", "args": ["run", "/path/to/github-security-mcp/src/index.ts"], "env": { "GITHUB_TOKEN": "ghp_your_token_here" } } } } ```
Cursor / Windsurf / 其他 MCP 客户端 使用相同的 JSON 配置格式。将命令指向您的安装路径。
### 开始审计 ``` You: "Audit my GitHub org for security misconfigurations" ``` 就是这样。代理会处理剩下的工作。 ## AI 能力展示 ### 完整组织审计 ``` You: "Run a complete security audit on our GitHub org" Agent: → github_run_all {org: "myorg", repo: "main-app"} → 45 checks across 6 categories → github_audit_report → "34 findings: 4 critical, 7 high, 12 medium. Critical #1: No branch protection on main (REPO-001) Critical #2: Script injection in deploy.yml (ACT-001) Critical #3: 3 critical Dependabot alerts unfixed 90+ days (REPO-007) Critical #4: Unresolved secret scanning alerts (SEC-002) Here are the exact fixes for each..." ``` ### Actions 工作流安全 ``` You: "Check our CI/CD workflows for supply chain risks" Agent: → github_check_workflow_injection Found ${{ github.event.issue.title }} in run: block (deploy.yml:47) → github_check_workflow_pinning 12 actions use tags instead of SHA pins → github_check_workflow_pr_target build.yml uses pull_request_target with checkout — critical risk → github_check_workflow_permissions Default GITHUB_TOKEN has write-all permissions → "4 supply chain risks found. The PR target + checkout pattern allows any fork to execute arbitrary code with write access to your repo. Fix this first." ``` ### 访问控制审查 ``` You: "Who has too much access to our repositories?" Agent: → github_check_team_permissions "platform" team has admin on 47 repos, only 3 members → github_check_collaborators 8 outside collaborators with write access → github_check_app_permissions "old-ci-bot" GitHub App has admin + all repos → github_check_pat_usage 14 classic PATs with repo scope (should be fine-grained) → "Reduce blast radius: restrict platform team to maintain, remove 3 stale outside collaborators, limit old-ci-bot to specific repos, migrate classic PATs to fine-grained." ``` ### Secret 泄露检测 ``` You: "Are we properly protecting secrets across our repos?" Agent: → github_check_secret_scanning Secret scanning disabled on 5 private repos → github_check_push_protection 3 push protection bypasses in the last month → github_check_secret_patterns No custom secret patterns defined → github_check_secret_scoping 2 org secrets available to all repos (should be scoped) → "Enable secret scanning on all repos, review the 3 bypasses, add custom patterns for internal API keys, and scope org secrets to only the repos that need them." ``` ## 工具参考 (39 个工具)
组织 (7) | 工具 | 描述 | |------|-------------| | `github_check_org_security` | 2FA 强制执行、默认仓库可见性、成员创建权限 | | `github_check_org_sso` | 通过 GraphQL 获取 SSO/SAML 配置 | | `github_check_org_members` | 外部协作者、僵尸成员检测 | | `github_check_org_apps` | OAuth 凭证授权、GitHub App 安装权限 | | `github_check_org_webhooks` | 不安全的 webhook URL (HTTP, 无 secret) | | `github_check_org_audit_log` | 可疑的审计日志活动 (Enterprise) | | `github_list_org_repos` | 列出组织中的所有仓库及安全元数据 |
仓库 (8) | 工具 | 描述 | |------|-------------| | `github_check_repo_branch_protection` | 默认分支的分支保护规则 | | `github_check_repo_secrets` | Secret 扫描和推送保护启用状态 | | `github_check_repo_code_scanning` | CodeQL / 代码扫描启用状态及未关闭的警报 | | `github_check_repo_dependabot` | Dependabot 启用状态、严重警报分级 | | `github_check_repo_settings` | SECURITY.md、私有漏洞报告、Fork 限制 | | `github_check_repo_webhooks` | 不安全的仓库级 webhook URL | | `github_check_repo_deploy_keys` | 部署密钥权限 (只读 vs 读写) | | `github_check_repo_codeowners` | CODEOWNERS 文件存在性及强制执行 |
Actions (8) | 工具 | 描述 | |------|-------------| | `github_check_workflow_injection` | `run:` 块中通过 `${{ github.event.* }}` 进行的脚本注入 | | `github_check_workflow_pr_target` | `pull_request_target` + checkout 模式 (严重) | | `github_check_workflow_permissions` | GITHUB_TOKEN 默认权限范围 | | `github_check_workflow_pinning` | 未固定的第三方操作 (标签 vs SHA) | | `github_check_workflow_runners` | 自托管 Runner 暴露风险 | | `github_check_workflow_environments` | 缺失的环境保护规则 | | `github_check_workflow_secrets` | 工作流中的 Secret 窃取模式 | | `github_check_workflow_oidc` | OIDC 主题声明自定义 |
Secrets (4) | 工具 | 描述 | |------|-------------| | `github_check_secret_scanning` | 覆盖范围缺口及未解决的警报 | | `github_check_push_protection` | 推送保护绕过追踪 | | `github_check_secret_patterns` | 自定义 Secret 模式配置 | | `github_check_secret_scoping` | 环境、仓库和组织级的 Secret 作用域 |
供应链 (4) | 工具 | 描述 | |------|-------------| | `github_check_dependency_graph` | 依赖图启用状态 | | `github_check_dependabot_updates` | Dependabot 安全更新配置 | | `github_check_sbom` | SBOM 生成能力 | | `github_check_vulnerabilities` | 已知漏洞、超过 90 天未修复的严重漏洞 |
访问控制 (4) | 工具 | 描述 | |------|-------------| | `github_check_team_permissions` | 团队在各仓库的权限级别 | | `github_check_collaborators` | 外部协作者访问审计 | | `github_check_app_permissions` | GitHub App 权限范围审查 | | `github_check_pat_usage` | Classic vs Fine-grained PAT 使用情况 |
元数据 (4) | 工具 | 描述 | |------|-------------| | `github_list_checks` | 浏览所有 45 项检查,按类别/严重程度筛选 | | `github_audit_summary` | 按类别、严重程度、状态聚合发现结果 | | `github_audit_report` | 完整的 Markdown 或 JSON 审计报告 | | `github_run_all` | 对组织/仓库执行所有检查 |
## 检查注册表 (45 项检查)
组织 (ORG-001 至 ORG-010) | ID | 检查项 | 严重程度 | |---|---|---| | ORG-001 | 未强制执行 2FA | CRITICAL | | ORG-002 | 默认仓库可见性为公开 | HIGH | | ORG-003 | 成员可创建公开仓库 | MEDIUM | | ORG-004 | 未配置 SSO/SAML | HIGH | | ORG-005 | 有访问权限的外部协作者 | MEDIUM | | ORG-006 | 僵尸组织成员 | LOW | | ORG-007 | 有风险的 OAuth App 授权 | HIGH | | ORG-008 | 权限过大的 GitHub App 安装 | HIGH | | ORG-009 | 不安全的 Webhook URL | MEDIUM | | ORG-010 | 可疑的审计日志活动 | INFO |
仓库 (REPO-001 至 REPO-013) | ID | 检查项 | 严重程度 | |---|---|---| | REPO-001 | 缺失或薄弱的分支保护 | CRITICAL | | REPO-002 | 未启用 Secret 扫描 | HIGH | | REPO-003 | 未启用推送保护 | HIGH | | REPO-004 | 未启用代码扫描 | MEDIUM | | REPO-005 | 存在未关闭的代码扫描警报 | HIGH | | REPO-006 | 未启用 Dependabot | MEDIUM | | REPO-007 | 严重 Dependabot 警报 | CRITICAL | | REPO-008 | 无 SECURITY.md 策略文件 | LOW | | REPO-009 | 私有漏洞报告已关闭 | LOW | | REPO-010 | 无限制的 Fork 设置 | LOW | | REPO-011 | 不安全的仓库 Webhook | MEDIUM | | REPO-012 | 读写型部署密钥 | HIGH | | REPO-013 | 缺少 CODEOWNERS 文件 | LOW |
Actions (ACT-001 至 ACT-008) | ID | 检查项 | 严重程度 | |---|---|---| | ACT-001 | 通过不可信输入进行脚本注入 | CRITICAL | | ACT-002 | pull_request_target 配合 checkout | CRITICAL | | ACT-003 | 权限过大的 GITHUB_TOKEN | HIGH | | ACT-004 | 未固定的第三方 Actions | MEDIUM | | ACT-005 | 自托管 Runner 暴露 | HIGH | | ACT-006 | 缺失环境保护规则 | MEDIUM | | ACT-007 | Secret 窃取模式 | HIGH | | ACT-008 | OIDC 配置错误 | MEDIUM |
Secrets (SEC-001 至 SEC-005) | ID | 检查项 | 严重程度 | |---|---|---| | SEC-001 | Secret 扫描覆盖缺口 | HIGH | | SEC-002 | 未解决的 Secret 扫描警报 | CRITICAL | | SEC-003 | 推送保护绕过 | HIGH | | SEC-004 | 无自定义 Secret 模式 | LOW | | SEC-005 | Secret 作用域过宽 | MEDIUM |
供应链 (SUP-001 至 SUP-005) | ID | 检查项 | 严重程度 | ---|---|---| | SUP-001 | 未启用依赖图 | MEDIUM | | SUP-002 | Dependabot 安全更新已关闭 | HIGH | | SUP-003 | 无 SBOM 生成 | LOW | | SUP-004 | 严重已知漏洞 | CRITICAL | | SUP-005 | 陈旧未修复漏洞 (>90 天) | HIGH |
访问控制 (ACC-001 至 ACC-004) | ID | 检查项 | 严重程度 | |---|---|---| | ACC-001 | 权限过大的团队访问 | HIGH | | ACC-002 | 外部协作者拥有写权限及以上 | MEDIUM | | ACC-003 | 权限范围过大的 GitHub Apps | HIGH | | ACC-004 | 拥有广泛范围的 Classic PAT | HIGH |
## 架构 ``` src/ ├── index.ts Entry point + MCP stdio ├── types/ │ └── index.ts CheckResult, ToolDef, ToolContext, ToolResult ├── github/ │ └── client.ts GitHubClientFactory (lazy Octokit + GraphQL) ├── protocol/ │ ├── tools.ts 39 tool definitions (Zod schemas) │ └── mcp-server.ts MCP server + stdio transport ├── org/ Organization checks (ORG-001..010) │ ├── security.ts 2FA, visibility, member privileges │ ├── sso.ts SSO/SAML via GraphQL │ ├── members.ts Outside collaborators, stale members │ ├── apps.ts OAuth apps, GitHub App installations │ ├── webhooks.ts Insecure webhook URLs │ └── audit-log.ts Suspicious audit log patterns ├── repo/ Repository checks (REPO-001..013) │ ├── branch-protection.ts Branch protection rules │ ├── secret-scanning.ts Secret scanning + push protection │ ├── code-scanning.ts CodeQL enabled, open alerts │ ├── dependabot.ts Dependabot enabled, critical alerts │ ├── settings.ts SECURITY.md, vuln reporting, forks │ ├── webhooks.ts Insecure repo webhooks │ ├── deploy-keys.ts Deploy key permissions │ └── codeowners.ts CODEOWNERS file ├── actions/ GitHub Actions checks (ACT-001..008) │ ├── injection.ts Script injection via untrusted inputs │ ├── pr-target.ts pull_request_target + checkout │ ├── permissions.ts GITHUB_TOKEN default permissions │ ├── pinning.ts Unpinned third-party actions │ ├── runners.ts Self-hosted runner exposure │ ├── environments.ts Environment protection rules │ ├── secrets.ts Secret exfiltration patterns │ └── oidc.ts OIDC configuration ├── secrets/ Secret management checks (SEC-001..005) │ ├── scanning.ts Coverage + alert triage │ ├── push-protection.ts Push protection bypasses │ ├── patterns.ts Custom secret patterns │ └── scoping.ts Env/repo/org secret scoping ├── supply-chain/ Supply chain checks (SUP-001..005) │ ├── dependency-graph.ts Dependency graph enabled │ ├── dependabot-updates.ts Security updates config │ ├── sbom.ts SBOM generation │ └── vulnerabilities.ts Known vulns, stale unfixed ├── access/ Access control checks (ACC-001..004) │ ├── teams.ts Team permission audit │ ├── collaborators.ts External collaborators │ ├── github-apps.ts GitHub App permissions │ └── tokens.ts Classic vs fine-grained PATs └── meta/ Aggregation + reporting ├── list-checks.ts CHECK_REGISTRY (45 checks) ├── summary.ts Findings aggregation ├── report.ts Markdown/JSON report └── run-all.ts Execute all checks ``` **设计决策:** - **单一 Octokit 实例** — GitHub API 是全局的 (无区域概念)。在首次 API 调用时延迟初始化。 - **统一的 CheckResult** — 每个检查返回相同的结构: checkId, severity, status, details, remediation。与 [cloud-audit-mcp](https://github.com/badchars/cloud-audit-mcp) 模式相同。 - **静态工作流分析** — Actions 检查通过 Contents API 获取 YAML 并使用正则分析。GitHub 没有解析后的工作流 API。 - **Enterprise 优雅降级** — Enterprise 专属功能 (审计日志、凭证授权、SSO) 返回 `NOT_APPLICABLE` 而非错误。 - **内存 findings** — 会话范围的 findings 数组。无数据库,无持久化。运行 `github_audit_summary` 或 `github_audit_report` 进行聚合。 - **4 个依赖项** — `@modelcontextprotocol/sdk`, `@octokit/rest`, `@octokit/graphql`, `zod`。除此之外别无其他。 ## 认证 | 令牌类型 | 所需权限范围 | |---|---| | **Classic PAT** | `repo`, `admin:org`, `admin:org_hook`, `admin:repo_hook` | | **Fine-grained PAT** (推荐) | 组织: 成员 + 管理 (读取)。仓库: 管理、代码扫描、Dependabot、Secret 扫描、Actions、环境、Webhook (读取) | | **GitHub App** | 与 Fine-grained PAT 相同的仓库/组织权限 | 令牌从 `GITHUB_TOKEN` 环境变量中读取。 ## MCP 安全套件的一部分 | 项目 | 领域 | 工具 | |---|---|---| | [hackbrowser-mcp](https://github.com/badchars/hackbrowser-mcp) | 浏览器安全测试 | 39 个工具, Firefox, 注入测试 | | [cloud-audit-mcp](https://github.com/badchars/cloud-audit-mcp) | 云安全 (AWS/Azure/GCP) | 38 个工具, 60+ 检查 | | **github-security-mcp** | GitHub 安全态势 | 39 个工具, 45 项检查 | ## 限制 - 需要具有适当权限范围的 GitHub PAT 或 GitHub App 令牌 - 某些检查需要 GitHub Enterprise Cloud (审计日志、凭证授权、SSO) — 这些在免费/Team 计划上会优雅地返回 NOT_APPLICABLE - Actions 工作流分析基于正则 (无 AST 解析) — 可能会遗漏复杂的注入模式 - 速率限制: GitHub API 允许认证用户每小时 5,000 次请求。包含许多仓库的完整组织审计可能会接近此限制 - macOS / Linux (Windows 尚未测试)

仅用于授权的安全测试和评估。
在审计任何组织之前,请务必确保您已获得适当的授权。

MIT License • 使用 Bun + TypeScript 构建

标签:AI安全, Bun, Chat Copilot, CISA项目, DevSecOps, GitHub Actions, GitHub安全, HTTP/HTTPS抓包, LLM工具, Secrets扫描, Streamlit, StruQ, 上游代理, 代码安全, 反取证, 大模型MCP, 安全评估, 态势感知, 文档安全, 漏洞枚举, 结构化查询, 自动化安全, 自动化攻击, 自动笔记, 访问控制