首頁  >  文章  >  後端開發  >  Golang:如何處理 google.golang.org/api 對 golang.org/x/net 的過時依賴項

Golang:如何處理 google.golang.org/api 對 golang.org/x/net 的過時依賴項

WBOY
WBOY轉載
2024-02-06 08:09:11822瀏覽

Golang:如何处理 google.golang.org/api 对 golang.org/x/net 的过时依赖项

問題內容

最近github.com dependabot 抱怨我的專案中的一些依賴項容易受到dos 的攻擊,具有「損壞或有風險的加密演算法”,並且存在“不受控制的資源消耗”的錯誤。

具體來說,它警告我有關 golang.org/x/net 模組的 cve-2022-27664、其他模組的 cve-2022-27191 和 cve-2022-32149。

我所做的是在所有使用的模組上執行“go get -u”。顯然,這並沒有解決問題。然後我開始用「go graph」尋找模組依賴關係。花了一段時間,這是我找到的依賴順序:

google.golang.org/[email protected] =>
[email protected] =>
google.golang.org/[email protected] =>
github.com/envoyproxy/[email protected] =>
google.golang.org/[email protected] =>
golang.org/x/[email protected] =>
google.golang.org/[email protected] =>
golang.org/x/[email protected]

這意味著2023 年3 月17 日起的最現代且更新的google.golang.org/api 軟體包會導致對2018 年起的golang.org/x/ net 的依賴。

我發現其他Google軟體包對舊網路模組有很多依賴:

cloud.google.com/go/[email protected] golang.org/x/[email protected]
github.com/googleapis/gax-go/[email protected] golang.org/x/[email protected]
[email protected] golang.org/x/[email protected]
golang.org/x/[email protected] golang.org/x/[email protected]
golang.org/x/[email protected] golang.org/x/[email protected]
google.golang.org/[email protected] golang.org/x/[email protected]
google.golang.org/[email protected] golang.org/x/[email protected]
google.golang.org/[email protected] golang.org/x/[email protected]
google.golang.org/[email protected] golang.org/x/[email protected]
golang.org/x/[email protected] golang.org/x/[email protected]
google.golang.org/[email protected] golang.org/x/[email protected]
golang.org/x/[email protected] golang.org/x/[email protected]
golang.org/x/[email protected] golang.org/x/[email protected]
golang.org/x/[email protected] golang.org/x/[email protected]
golang.org/x/[email protected] golang.org/x/[email protected]
google.golang.org/[email protected] golang.org/x/[email protected]
golang.org/x/[email protected] golang.org/x/[email protected]
google.golang.org/[email protected] golang.org/x/[email protected]
golang.org/x/[email protected] golang.org/x/[email protected]
google.golang.org/[email protected] golang.org/x/[email protected]
golang.org/x/[email protected] golang.org/x/[email protected]
google.golang.org/[email protected] golang.org/x/[email protected]
google.golang.org/[email protected] golang.org/x/[email protected]

我檢查了 github.com/googleapis/google-api-go-client 儲存庫並發現了此問題 https://github.com/googleapis/google-api-go-client/issues/1048 我說同樣的問題,但後來用戶 hashier 說,由於 go list -m all 命令顯示最新版本,所以這不是問題。

所以,主要問題是:這是否是一個問題以及為什麼?

我只是不知道這裡應該修復什麼,github dependabot 檢查或 google-api-go-client 模組依賴項。


正確答案


是時候回答這個問題了。

當我嘗試使用go mod graph 在單獨的草稿儲存庫中一一檢查專案中的所有套件時,這些易受攻擊的依賴項來自另一個儲存庫:github .com/go-gorm/postgres

所以,我錯誤地確定了易受攻擊的依賴項來自何處。顯然這是由於巨大的依賴關係圖造成的:

[0] $ go mod graph | wc
    667    1334   56113

如果有人正在尋找一種視覺化專案依賴關係的方法,這裡是:

go mod graph | modgv | dot -Tsvg -o graph.svg

回到最初的問題。這是由於 github.com/go-gorm/postgres 使用舊版本的 go 造成的。據我了解,修復它的唯一方法是將 go 版本升級到 1.18。如果版本較低,go mod graph會顯示很多易受攻擊的套件。

以上是Golang:如何處理 google.golang.org/api 對 golang.org/x/net 的過時依賴項的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:stackoverflow.com。如有侵權,請聯絡admin@php.cn刪除