Migration From V4
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
相較於第 4 版 (具體來說是第 4 版更新 API),Google 安全瀏覽第 5 版的一大進步在於資料的新鮮度和涵蓋範圍。由於保護機制高度依賴用戶端維護的本機資料庫,因此本機資料庫更新的延遲和大小是導致保護機制失效的主要原因。在第 4 版中,一般用戶端需要 20 到 50 分鐘才能取得最新版的威脅清單。很遺憾,網路釣魚攻擊的傳播速度很快:截至 2021 年,有 60% 的攻擊網站存活時間不到 10 分鐘。分析結果顯示,約有 25% 至 30% 的網路釣魚防護措施失效,都是因為資料過時。此外,部分裝置無法管理所有 Google 安全瀏覽威脅清單,而這類清單會隨著時間不斷擴大。
如果您目前使用 v4 Update API,可以從 v4 無縫遷移至 v5,不必重設或清除本機資料庫。本節說明如何執行這項操作。
轉換清單更新
與 V4 不同的是,V5 清單只會依名稱識別,V4 則是依威脅類型、平台類型和威脅項目類型元組識別。如果多個 v5 清單可能共用相同的威脅類型,這項功能就能提供彈性。第 5 版已移除平台類型和威脅項目類型。
在第 4 版中,使用者會使用 threatListUpdates.fetch 方法下載清單。在第 5 版中,使用者會切換至 hashLists.batchGet 方法。
請對要求進行下列變更:
- 完全移除 v4
ClientInfo
物件。您不必使用專屬欄位提供用戶端 ID,只要使用眾所周知的 User-Agent 標頭即可。雖然我們並未規定在這個標頭中提供用戶端 ID 的格式,但建議您直接加入原始用戶端 ID 和用戶端版本,並以空格字元或斜線字元分隔。
- 針對每個 v4
ListUpdateRequest
物件:
- 從可用清單中查閱對應的 v5 清單名稱,並在 v5 要求中提供該名稱。
- 移除不必要的欄位,例如
threat_entry_type
或 platform_type
。
- v4 中的
state
欄位與 v5 中的 versions
欄位直接相容。在第 5 版中,您可以使用 versions
欄位,傳送第 4 版中會使用 state
欄位傳送至伺服器的相同位元組字串。
- 對於 v4 限制,v5 使用簡化版本,稱為
SizeConstraints
。應捨棄 region
等其他欄位。
請對回應進行下列變更:
- v4 列舉
ResponseType
只是由名為 partial_update
的布林欄位取代。
minimum_wait_duration
欄位現在可以為零或省略。如果是,系統會要求用戶端立即提出其他要求。只有在用戶端於 SizeConstraints
中指定的最大更新大小限制小於資料庫大小上限時,才會發生這種情況。
- 您需要調整 32 位元整數的 Rice 解碼演算法。兩者的差異在於編碼資料的位元組順序不同。在 v4 和 v5 中,32 位元雜湊前置字元都會依字典順序排序。但在 v4 中,這些前置字元排序時會視為小端,而在 v5 中,這些前置字元排序時會視為大端。也就是說,由於字典排序與大端位元組的數字排序相同,因此用戶端不需要進行任何排序。您可以在 這裡查看 Chromium 實作的 v4 版本排序範例。這類排序方式可以移除。
- 其他雜湊長度也需要實作 Rice 解碼演算法。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-10 (世界標準時間)。
[null,null,["上次更新時間:2025-08-10 (世界標準時間)。"],[],[],null,["# Migration From V4\n\nOne significant improvement of Google Safe Browsing v5 over v4 (specifically, [the v4 Update API](/safe-browsing/v4/update-api)) is data freshness and coverage. Since the protection highly depends on the client-maintained local database, the delay and size of the local database update is the main contributor of the missed protection. In v4, the typical client takes 20 to 50 minutes to obtain the most up-to-date version of threat lists. Unfortunately, phishing attacks spread fast: as of 2021, 60% of sites that deliver attacks live less than 10 minutes. Our analysis shows that around 25-30% of missing phishing protection is due to such data staleness. Further, some devices are not equipped to manage the entirety of the Google Safe Browsing threat lists, which continues to grow larger over time.\n\nIf you are currently using the [v4 Update API](/safe-browsing/v4/update-api), there is a seamless migration path from v4 to v5 without having to reset or erase the local database. This section documents how to do that.\n\n### Converting List Updates\n\nUnlike V4, where lists are identified by the tuple of threat type, platform type, threat entry type, in v5 lists are simply identified by name. This provides flexibility when multiple v5 lists could share the same threat type. Platform types and threat entry types are removed in v5.\n\nIn v4, one would use the [threatListUpdates.fetch method](/safe-browsing/reference/rest/v4/threatListUpdates/fetch) to download lists. In v5, one would switch to the [hashLists.batchGet method](/safe-browsing/reference/rest/v5/hashLists/batchGet).\n\nThe following changes should be made to the request:\n\n1. Remove the [v4 `ClientInfo` object](/safe-browsing/reference/rest/v4/ClientInfo) altogether. Instead of supplying a client's identification using a dedicated field, simply use the well-known [User-Agent header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent). While there is no prescribed format for supplying the client identification in this header, we suggest simply including the original client ID and client version separated by a space character or a slash character.\n2. For each [v4 `ListUpdateRequest` object](/safe-browsing/reference/rest/v4/threatListUpdates/fetch#listupdaterequest):\n - Look up the corresponding v5 list name from the [available lists](/safe-browsing/reference/Local.Database#available-lists) and supply that name in the v5 request.\n - Remove unneeded fields such as `threat_entry_type` or `platform_type`.\n - The `state` field in v4 is directly compatible with the v5 `versions` field. The same byte string that would be sent to the server using the `state` field in v4 can simply be sent in v5 using the `versions` field.\n - For the v4 constraints, v5 uses a simplified version called [`SizeConstraints`](/safe-browsing/reference/rest/v5/SizeConstraints). Additional fields such as `region` should be dropped.\n\nThe following changes should be made to the response:\n\n1. The v4 [enum `ResponseType`](/safe-browsing/reference/rest/v4/threatListUpdates/fetch#ResponseType) is simply replaced by a boolean field named `partial_update`.\n2. The `minimum_wait_duration` field can now be zero or omitted. If it is, the client is requested to immediately make another request. This only happens when the client specifies in `SizeConstraints` a smaller constraint on max update size than the max database size.\n3. The Rice decoding algorithm for 32-bit integers will need to be adjusted. The difference is that the encoded data are encoded with a different endianness. In both v4 and v5, 32-bit hash prefixes are sorted lexicographically. But in v4, those prefixes are treated as little endian when sorted, whereas in v5 those prefixes are treated as big endian when sorted. This means that the client does not need to do any sorting, since lexicographic sorting is identical to numeric sorting with big endian. An example of this sort in the Chromium implementation of v4 can be found [here](https://source.chromium.org/chromium/chromium/src/+/main:components/safe_browsing/core/browser/db/v4_rice.cc;l=144-146;drc=8ba1bad80dc22235693a0dd41fe55c0fd2dbdabd). Such sorting can be removed.\n4. The Rice decoding algorithm will need to be implemented for other hash lengths as well.\n\n### Converting Hash Searches\n\nIn v4, one would use the [fullHashes.find method](/safe-browsing/reference/rest/v4/fullHashes/find) to get full hashes. The equivalent method in v5 is [the hashes.search method](/safe-browsing/reference/rest/v5/hashes/search).\n\nThe following changes should be made to the request:\n\n1. Structure the code to only send hash prefixes that are exactly 4 bytes in length.\n2. Remove the [v4 `ClientInfo` objects](/safe-browsing/reference/rest/v4/ClientInfo) altogether. Instead of supplying a client's identification using a dedicated field, simply use the well-known [User-Agent header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent). While there is no prescribed format for supplying the client identification in this header, we suggest simply including the original client ID and client version separated by a space character or a slash character.\n3. Remove the `client_states` field. It is no longer necessary.\n4. It is no longer needed to include `threat_types` and similar fields.\n\nThe following changes should be made to the response:\n\n1. The `minimum_wait_duration` field has been removed. The client can always issue a new request on an as-needed basis.\n2. The [v4 `ThreatMatch` object](/safe-browsing/reference/rest/v4/ThreatMatch) has been simplified into the [`FullHash`](/safe-browsing/reference/rest/v5/hashes/search#FullHash) object.\n3. Caching has been simplified into a single cache duration. See the above procedures for interacting with the cache."]]