安全漏洞修復技能 Security Vulnerability Fix Skill
修復 npm 依賴安全漏洞的標準化工作流程。 A standardized workflow for fixing npm dependency security vulnerabilities.
適用情境 When to Use
- •收到 Dependabot security alerts
- •執行
npm audit發現漏洞 - •需要升級有 CVE 的套件
- •發布安全修補版本 (PATCH release)
工作流程 Workflow
Phase 1: 漏洞分析 Vulnerability Analysis
- •
查詢所有安全警告
bashgh api repos/{owner}/{repo}/dependabot/alerts --jq '.[] | {number: .number, state: .state, severity: .security_advisory.severity, package: .security_vulnerability.package.name, summary: .security_advisory.summary}' - •
深入分析特定警告 (取得 CVE、修復版本、CVSS 分數)
bashgh api repos/{owner}/{repo}/dependabot/alerts/{alert_number} - •
確認目前安裝版本
bashnpm ls {package_name} - •
評估風險
- •Critical/High: 立即修復
- •Medium: 排程修復
- •Low: 評估是否需要
Phase 2: 版本規劃 Version Planning
- •
遵循語意化版本規則:
- •純安全修補 → PATCH (x.y.Z)
- •含新功能 → MINOR (x.Y.0)
- •有 breaking changes → MAJOR (X.0.0)
- •
檢查修復版本是否可用
bashnpm view {package_name} versions --json | tail -5
Phase 3: 實施修復 Implementation
- •
更新 package.json
- •修改依賴版本
- •更新專案版本號
- •
更新 CHANGELOG.md (雙語格式)
markdown## [x.y.z] - YYYY-MM-DD ### 安全性修復 Security Fixes - **修復 {套件名稱} {漏洞類型} (CVE-XXXX-XXXX)** (Fix {package} {vulnerability type}) - 升級 `{package}` 從 x.x.x 至 x.x.x Upgraded `{package}` from x.x.x to x.x.x - 嚴重程度 Severity: {severity} (CVSS: x.x) - 關閉 Dependabot Alert #{number} Closes Dependabot Alert #{number} - •
安裝並驗證
bashnpm install npm run package # 或 npm run build npm run test
- •
產生 VSIX (VS Code 擴充功能專案)
bashnpx @vscode/vsce package
Phase 4: 更新 SECURITY.md Maintenance
如果專案根目錄有 SECURITY.md 文件,需同步更新:
- •
檢查是否有 Known Issues 區塊記錄此漏洞
- •如有記錄「等待上游修復」的漏洞,現已修復 → 移除該區塊
- •如果是全新漏洞且無法立即修復 → 新增到 Known Issues
- •
更新 Supported Versions 區塊
- •確保支援版本與目前發布版本一致
- •範例:
0.51.x→0.52.x
- •
更新 Last updated 日期
範例格式:
markdown
# Security Policy ## Supported Versions | Version | Supported | | ------- | ------------------ | | 0.52.x | :white_check_mark: | | < 0.51 | :x: | ## Reporting a Vulnerability Please report security vulnerabilities by opening a [GitHub Security Advisory](...). --- _Last updated: YYYY-MM-DD_
Phase 5: 發布流程 Release Process
- •
Git 提交 (遵循 Conventional Commits)
bashgit add package.json package-lock.json CHANGELOG.md SECURITY.md git commit -m "chore(deps): 修復 {package} {漏洞類型} ({CVE})" - •
建立標籤
bashgit tag -a v{version} -m "Release v{version} - Security patch for {CVE}" - •
推送至遠端
bashgit push origin {branch} --follow-tags - •
建立 GitHub Release (雙語發布說明)
bashgh release create v{version} --title "{Project} v{version} - 安全修補 / Security Patch" --notes-file release-notes.md {vsix_file} - •
清理暫存檔案
bashrm release-notes.md *.vsix
Phase 5: 驗證修復 Verification
- •
確認警告狀態
bashgh api repos/{owner}/{repo}/dependabot/alerts/{number} --jq '{state: .state, fixed_at: .fixed_at}' - •
如果警告未自動關閉 (Dependabot 掃描延遲)
- •先確認 package-lock.json 在 GitHub 上版本正確
- •手動關閉警告:
bashgh api repos/{owner}/{repo}/dependabot/alerts/{number} -X PATCH -f state="dismissed" -f dismissed_reason="fix_started" -f dismissed_comment="Upgraded to {version} in commit {sha}. See v{release_version} release."
雙語發布說明範本 Bilingual Release Notes Template
參考 release-notes-template.md 建立發布說明。
檢查清單 Checklist
- • 查詢並分析安全警告
- • 確認修復版本可用
- • 更新 package.json (依賴 + 版本號)
- • 更新 CHANGELOG.md (雙語格式)
- • 更新 SECURITY.md (移除已修復漏洞、更新支援版本)
- • npm install + build + test 通過
- • 產生 VSIX (如適用)
- • Git commit 遵循 Conventional Commits
- • 建立版本標籤
- • 推送至遠端
- • 建立 GitHub Release (雙語發布說明)
- • 驗證警告已關閉
相關工具 Related Tools
- •
gh api- GitHub CLI API 操作 - •
npm audit- 本地漏洞掃描 - •
npm ls- 查看依賴樹 - •
npx @vscode/vsce package- VS Code 擴充功能打包