Community研究与数据分析github.com

Nick2bad4u/Github-Security-CodeScanning-Alerts-Skill

一个用于管理 GitHub 代码扫描、安全、Dependabot 等警报的 Copilot / AI 技能。

Github-Security-CodeScanning-Alerts-Skill 是什么?

该技能是一个 AI 代理技能,旨在高效管理和操作 GitHub 仓库中的安全警报。它支持代码扫描、Dependabot、Dependabot 恶意软件、密钥扫描以及仓库安全设置等全面功能。主要优势在于其仓库无关性:它可以自动从 git 远程仓库检测仓库所有者/名称和 GitHub 主机,无需硬编码路径。该技能通过环境变量(如 `GITHUB_TOKEN`)进行安全身份验证,避免在命令行中暴露令牌。它提供丰富的命令,包括 `summary`、`export-alerts`、`bulk-update-alerts` 以及各种列表/显示/更新操作,并支持 JSON 输出以便集成。它尤其擅长处理 Dependabot 恶意软件警报,通过查询 GitHub 建议数据库来识别恶意软件,确保准确性。该技能支持 macOS、Windows 和 Linux(通过 Python 3),并兼容 GitHub.com 和 GitHub Enterprise Server。最佳实践强调安全使用 `--dry-run` 进行变更预览,并且除非用户明确确认,否则默认对敏感信息进行脱敏处理。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add Nick2bad4u/Github-Security-CodeScanning-Alerts-Skill

Installed? Explore more 研究与数据分析 skills: affaan-m/uspto-database, affaan-m/scholar-evaluation, affaan-m/literature-review · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

GitHub 安全警报管理

概述

当用户要求检查或管理 GitHub 仓库安全警报时,使用此技能,包括:

  • 代码扫描警报
  • Dependabot 警报
  • Dependabot 恶意软件警报
  • 密钥扫描警报
  • 密钥扫描警报位置
  • 密钥扫描扫描历史
  • 仓库安全设置概览
  • 跨仓库的原始 GitHub 安全 API 检查
  • 用于离线分类或报告工作流的批量警报导出
  • 用于高容量清理工作流的批量警报更新

内置助手是仓库无关的:

  • 指定 --repo 指向任何本地检出路径
  • 让它从 git 远程仓库自动检测 owner/repo 和 GitHub 主机
  • 或显式传递 --repository owner/repo
  • 通过环境变量进行身份验证,而不是在命令行上放置令牌
  • 可选覆盖 API 或 Web 基础 URL,以支持自定义环境

兼容性

需要 Python 3。 直接使用 GitHub REST API,通过环境变量(如 GITHUB_TOKEN 或 GH_TOKEN)提供令牌。 支持 GitHub.com 和标准 GHES API 基础 URL(从 git 远程仓库推导),并提供原始 API 回退以处理尚未封装的功能。

调用提示

当目标是本地检出时,使用 repo,默认为 .。 当自动检测不足时,使用可选的 repository、api_base_url、web_base_url 和 token_env 值。 常见命令包括 summary、export-alerts、bulk-update-alerts、repo-security-overview、list-code-scanning、show-code-scanning、update-code-scanning、list-dependabot、show-dependabot、update-dependabot、list-malware、show-malware、update-malware、list-secret-scanning、show-secret-scanning、update-secret-scanning、list-secret-locations、secret-scan-history 和 api-call。

安全模型

请勿将 GitHub 令牌粘贴到命令参数中。 除非用户明确要求未脱敏的密钥值并确认暴露风险,否则不要使用 --show-secret-values。优先使用脱敏的警报元数据、密钥位置、有效性和解决状态。如果需要未脱敏的输出进行修复,请勿将密钥材料粘贴到聊天、问题评论、PR、提交、日志或保存的报告中。

首选模式:

$env:GITHUB_TOKEN = Get-Secret GITHUB_TOKEN -AsPlainText

如果仓库使用不同的环境变量名,请先导出该变量,或使用 --token-env 传递变量名。

示例:

python "<path-to-skill>/scripts/manage_github_security_alerts.py" summary --repo "."
python "<path-to-skill>/scripts/manage_github_security_alerts.py" summary --repo "." --token-env GITHUB_TOKEN

共享 CLI 选项

  • repo:目标仓库检出的路径(默认 .)
  • repository:可选的显式 owner/repo 覆盖
  • api_base_url:可选的显式 API 基础 URL 覆盖
  • web_base_url:可选的显式 Web 基础 URL 覆盖,用于渲染链接
  • token_env:可选的包含令牌的环境变量名;可重复以支持回退
  • json:可选的机器可读输出标志

关于恶意软件警报的重要说明

GitHub 将恶意软件发现结果显示为 Dependabot 恶意软件警报。

GitHub 不提供单独的仓库警报类型及其专用的 REST 接口。因此,内置助手将恶意软件视为 Dependabot 警报的一个过滤子集,并将每个警报的建议 GHSA 与 GitHub 建议数据库进行交叉引用,以识别类型为 malware 的建议。

这意味着:

  • list-malware、show-malware 和 update-malware 依赖于 Dependabot 警报 API
  • 恶意软件分类在 GitHub.com 上最准确,因为建议数据库端点可用
  • 如果目标主机上无法进行建议类型查找,助手会报告该状态,而不是无声地猜测

快速开始

1. 检查当前安全状态

python "<path-to-skill>/scripts/manage_github_security_alerts.py" summary --repo "."

2. 查看仓库安全设置概览

python "<path-to-skill>/scripts/manage_github_security_alerts.py" repo-security-overview --repo "."

2.5 导出完整的警报集以进行批量分类

python "<path-to-skill>/scripts/manage_github_security_alerts.py" export-alerts --repo "." --json

3. 代码扫描列表示例

使用共享输入 repo、repository、api_base_url、web_base_url、token_env 和 json,以及代码扫描过滤器,如 state、severity、tool_name、tool_guid、ref 和 pr。 输出 code_scanning_alerts,渲染为文本或机器可读的 JSON。

python "<path-to-skill>/scripts/manage_github_security_alerts.py" list-code-scanning --repo "." --state open --severity high,error

3.5 批量关闭或批量重新打开警报

python "<path-to-skill>/scripts/manage_github_security_alerts.py" bulk-update-alerts --repo "." --surface code-scanning --select-state open --target-state dismissed --dismissed-reason "false positive" --comment "Reviewed and intentionally dismissed." --limit 10 --dry-run --json

python "<path-to-skill>/scripts/manage_github_security_alerts.py" bulk-update-alerts --repo "." --surface dependabot --select-state open --target-state dismissed --dismissed-reason tolerable_risk --comment "Accepted until the next dependency refresh." --limit 25 --dry-run --json

python "<path-to-skill>/scripts/manage_github_security_alerts.py" bulk-update-alerts --repo "." --surface secret-scanning --select-state open --target-state resolved --resolution used_in_tests --limit 25 --dry-run --json

4. 关闭或重新打开代码扫描警报

python "<path-to-skill>/scripts/manage_github_security_alerts.py" update-code-scanning --repo "." --alert 42 --state dismissed --dismissed-reason false_positive --comment "False positive after manual review." --dry-run
python "<path-to-skill>/scripts/manage_github_security_alerts.py" update-code-scanning --repo "." --alert 42 --state open

5. Dependabot 列表示例

使用共享输入 repo、repository、api_base_url、web_base_url、token_env 和 json,以及 Dependabot 过滤器,如 state、severity、ecosystem、package、manifest、has、assignee 和 scope。 输出 dependabot_alerts,渲染为文本或机器可读的 JSON。

python "<path-to-skill>/scripts/manage_github_security_alerts.py" list-dependabot --repo "." --state open --ecosystem npm --has patch

6. 关闭或重新打开 Dependabot 警报

python "<path-to-skill>/scripts/manage_github_security_alerts.py" update-dependabot --repo "." --alert 7 --state dismissed --dismissed-reason tolerable_risk --comment "Accepted until next quarterly upgrade." --dry-run
python "<path-to-skill>/scripts/manage_github_security_alerts.py" update-dependabot --repo "." --alert 7 --state open

7. 恶意软件列表示例

使用共享输入 repo、repository、api_base_url、web_base_url、token_env 和 json,以及基于 Dependabot 的恶意软件过滤器,如 state、severity、ecosystem、package、manifest 和 has。 输出 malware_alerts 以及来自建议类型分类的任何 lookup_failures。

python "<path-to-skill>/scripts/manage_github_security_alerts.py" list-malware --repo "." --state open

8. 密钥扫描列表示例

使用共享输入 repo、repository、api_base_url、web_base_url、token_env 和 json,以及密钥扫描过滤器,如 state、secret_type、resolution、assignee、validity,以及泄露或多仓库标志。 输出 secret_scanning_alerts,默认对密钥值进行脱敏。

python "<path-to-skill>/scripts/manage_github_security_alerts.py" list-secret-scanning --repo "." --state open

默认情况下密钥值隐藏。请保持此默认设置,除非用户明确确认需要未脱敏的密钥输出。

9. 解决或重新打开密钥扫描警报

python "<path-to-skill>/scripts/manage_github_security_alerts.py" update-secret-scanning --repo "." --alert 11 --state resolved --resolution revoked --comment "Token revoked and rotated." --dry-run
python "<path-to-skill>/scripts/manage_github_security_alerts.py" update-secret-scanning --repo "." --alert 11 --state open

10. 显示密钥位置和扫描历史

python "<path-to-skill>/scripts/manage_github_security_alerts.py" list-secret-locations --repo "." --alert 11
python "<path-to-skill>/scripts/manage_github_security_alerts.py" secret-scan-history --repo "."

11. 使用原始 API 回退以处理尚未封装的功能

python "<path-to-skill>/scripts/manage_github_security_alerts.py" api-call --repo "." --endpoint /repos/OWNER/REPO/code-scanning/default-setup

工作流

  1. 安全地解析身份验证。
    • 优先使用环境变量,如 GITHUB_TOKEN。
    • 如果需要,首先从机密管理器加载到环境变量中。
    • 切勿在日志或聊天输出中打印令牌。
  2. 解析目标仓库。
    • 优先使用 --repo 并从 git 远程仓库自动检测。
    • 当本地检出不可用或非标准时,回退到 --repository owner/repo。
  3. 检查当前发现结果。
    • 首先运行 summary。
    • 当需要更全面的多表面 JSON 快照以进行批量分类或外部报告时,使用 export-alerts。
    • 使用您关心的警报类型的 list/show 命令。
    • 当问题是关于启用状态或可用安全设置时,使用 repo-security-overview。
  4. 分类发现结果。
    • 适当时修复代码或依赖配置中的真实缺陷。
    • 仅在有明确理由时关闭警报。
    • 当之前的关闭或解决不再有效时,重新打开警报。
    • 当仓库有数十或数百个已经审查、错误分类且需要相同操作的警报时,使用 bulk-update-alerts。
  5. 谨慎应用变更。
    • 对于高风险更改,优先使用 --dry-run。
    • 添加简短、可操作的关闭或解决注释。
    • 记住写入操作需要相应的 GitHub 权限。
  6. 验证更改后的状态。
    • 重新运行相关的 list/show 命令。
    • 对于代码或依赖修复,如果您希望警报自然消失,请等待下一个 GitHub 分析周期。

捆绑资源

帮助脚本

scripts/manage_github_security_alerts.py 是用于 GitHub 仓库安全警报的仓库无关帮助脚本。

支持的命令:

  • summary
  • export-alerts
  • bulk-update-alerts
  • repo-security-overview
  • list-code-scanning
  • show-code-scanning
  • update-code-scanning
  • list-dependabot
  • show-dependabot
  • update-dependabot
  • list-malware
  • show-malware
  • update-malware
  • list-secret-scanning
  • show-secret-scanning
  • update-secret-scanning
  • list-secret-locations
  • secret-scan-history
  • api-call

实现模块:

  • github_security_api.py
  • github_security_cli.py
  • github_security_common.py
  • github_security_operations.py
  • github_security_render.py

示例:

python "<path-to-skill>/scripts/manage_github_security_alerts.py" summary --repo "." --json
python "<path-to-skill>/scripts/manage_github_security_alerts.py" export-alerts --repo "." --json
python "<path-to-skill>/scripts/manage_github_security_alerts.py" bulk-update-alerts --repo "." --surface code-scanning --select-state open --target-state dismissed --dismissed-reason "false positive" --comment "Reviewed and intentionally dismissed." --limit 10 --dry-run --json
python "<path-to-skill>/scripts/manage_github_security_alerts.py" list-code-scanning --repo "." --state open --per-page 100 --json
python "<path-to-skill>/scripts/manage_github_security_alerts.py" update-code-scanning --repo "." --alert 42 --state dismissed --dismissed-reason false_positive --comment "False positive after review." --dry-run
python "<path-to-skill>/scripts/manage_github_security_alerts.py" list-dependabot --repo "." --state open --ecosystem npm --json
python "<path-to-skill>/scripts/manage_github_security_alerts.py" list-malware --repo "." --json
python "<path-to-skill>/scripts/manage_github_security_alerts.py" update-dependabot --repo "." --alert 7 --state dismissed --dismissed-reason tolerable_risk --comment "Accepted temporarily." --dry-run
python "<path-to-skill>/scripts/manage_github_security_alerts.py" list-secret-scanning --repo "." --state open --json
python "<path-to-skill>/scripts/manage_github_security_alerts.py" update-secret-scanning --repo "." --alert 11 --state resolved --resolution revoked --comment "Revoked and rotated." --dry-run
python "<path-to-skill>/scripts/manage_github_security_alerts.py" list-secret-locations --repo "." --alert 11 --json
python "<path-to-skill>/scripts/manage_github_security_alerts.py" secret-scan-history --repo "." --json
python "<path-to-skill>/scripts/manage_github_security_alerts.py" api-call --repo "." --endpoint /repos/OWNER/REPO/dependabot/alerts --query-param state=open --json

相关技能