使用 Go 编写的自动化工具,用于扫描 GitHub 仓库,检测存在漏洞的 Next.js 版本(CVE-2025-66478),并自动创建包含特定安全补丁的 Pull Request。
请确保你的环境中已安装并配置了以下工具:
gh)在运行此工具之前,你必须在 GitHub CLI 中完成身份验证:
gh auth login
# Select "SSH" as git protocol and "GitHub.com"
克隆此仓库(保存了 main.go 脚本的位置):
git clone <your-tools-repo-url>
cd auto-patcher
安装 Go 依赖:
我们需要 semver 库来智能比较版本。
go get github.com/Masterminds/semver/v3
go mod tidy
目前,配置直接在 main.go 文件的常量中进行。运行前请检查以下行:
main 函数中,如果你希望将搜索范围限制到特定组织或用户,请编辑 gh 命令:
// main.go
cmd := exec.Command("gh", "repo", "list", "YOUR_ORG_OR_USER", "--limit", "100", ...)
const (
TargetBranch = "fix/security-nextjs-cve"
PRTitle = "fix(deps): upgrade next.js to patch CVE-2025-66478"
)
直接运行主脚本:
go run main.go
gh repo list 列出仓库。/tmp/repo-fixer-*)。package.json 文件。next 版本与安全规则表(SemVer)进行比较。package.json,将其升级到所需的最低安全版本。此脚本应用严格规则以避免破坏兼容性(不会更新到最新版本,而是更新到当前次版本的安全补丁):
| Detected Version | Applied Patch |
|---|---|
查看 main.go 中的 nextJsRules 以获取完整列表。
15.0.x^15.0.5 |
15.1.x | ^15.1.9 |
15.2.x | ^15.2.6 |
| ... | ... |