IDE 中的漏洞掃描

返回 Go 安全性

Go 語言伺服器 整合的編輯器,例如 安裝了 Go 擴充功能的 VS Code,可以偵測相依項中的漏洞。

偵測相依項中漏洞有兩種模式。兩種模式都由 Go 漏洞資料庫 支援,並且相輔相成。

Vulncheck

Go:切換 Vulncheck (vulncheck.mp4)

這些功能在 gopls v0.11.0 或更新版本中提供。請在 go.dev/s/vsc-vulncheck-feedback 分享你的意見回饋。

編輯器特定說明

VS Code

Go 擴充功能提供與 gopls 的整合。需要以下設定才能啟用漏洞掃描功能

"go.diagnostic.vulncheck": "Imports", // enable the imports-based analysis by default.
"gopls": {
  "ui.codelenses": {
    "run_govulncheck": true  // "Run govulncheck" code lens on go.mod file.
  }
}

「Go 切換 Vulncheck」 命令可用於為目前的 workspace 開啟或關閉基於匯入的分析。

Vim/NeoVim

使用 coc.nvim 時,以下設定將啟用基於匯入的分析。

{
    "codeLens.enable": true,
    "languageserver": {
        "go": {
            "command": "gopls",
            ...
            "initializationOptions": {
                "vulncheck": "Imports",
            }
        }
    }
}

注意事項和警告