Migration From V4
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
与第 4 版(尤其是 第 4 版 Update API)相比,Google 安全浏览第 5 版的一项重大改进是数据的新鲜度和覆盖面。由于保护高度依赖于客户端维护的本地数据库,因此本地数据库更新的延迟和大小是导致保护缺失的主要原因。在 v4 中,典型客户端需要 20 到 50 分钟才能获取最新版本的威胁列表。遗憾的是,钓鱼式攻击的传播速度很快:截至 2021 年,60% 的攻击网站的存活时间不到 10 分钟。我们的分析表明,大约 25-30% 的钓鱼式攻击防护缺失是由于此类数据过时造成的。此外,某些设备无法管理 Google 安全浏览威胁列表的全部内容,而该列表会随着时间的推移而不断扩大。
如果您目前使用的是 v4 Update API,则可以从 v4 无缝迁移到 v5,而无需重置或清除本地数据库。本部分介绍了如何执行此操作。
转换列表更新
与 V4 不同的是,V4 中的列表是通过威胁类型、平台类型、威胁条目类型的元组来标识的,而 V5 中的列表仅通过名称来标识。这样一来,当多个 v5 列表可能共享同一威胁类型时,便可灵活应对。在 v5 中,平台类型和威胁条目类型已被移除。
在 v4 中,可以使用 threatListUpdates.fetch 方法下载列表。在 v5 中,用户可以改用 hashLists.batchGet 方法。
应针对请求进行以下更改:
- 完全移除 v4
ClientInfo
对象。您只需使用众所周知的 User-Agent 标头,即可提供客户的身份信息,而无需使用专用字段。虽然此标头中没有规定提供客户端标识的格式,但我们建议您仅包含原始客户端 ID 和客户端版本,并用空格字符或斜杠字符分隔。
- 对于每个 v4
ListUpdateRequest
对象:
- 从可用列表中查找相应的 v5 列表名称,并在 v5 请求中提供该名称。
- 移除不需要的字段,例如
threat_entry_type
或 platform_type
。
- v4 中的
state
字段与 v5 中的 versions
字段直接兼容。使用 v4 中的 state
字段发送到服务器的相同字节字符串只需使用 v5 中的 versions
字段即可发送。
- 对于 v4 限制,v5 使用了一个简化版本,称为
SizeConstraints
。应舍弃 region
等其他字段。
应在回答中进行以下更改:
- v4 枚举
ResponseType
已被一个名为 partial_update
的布尔值字段取代。
minimum_wait_duration
字段现在可以为零或省略。如果为 1,则要求客户端立即发出另一个请求。只有当客户端在 SizeConstraints
中指定的最大更新大小限制小于最大数据库大小时,才会发生这种情况。
- 需要调整 32 位整数的 Rice 解码算法。不同之处在于,编码后的数据采用不同的字节序进行编码。在 v4 和 v5 中,32 位哈希前缀均按字典顺序排序。但在 v4 中,这些前缀在排序时会被视为小端,而在 v5 中,这些前缀在排序时会被视为大端。这意味着客户端无需进行任何排序,因为字典顺序排序与大端字节序的数字排序相同。点击此处可查看 Chromium 实现的 v4 中的此类示例。您可以移除此类排序。
- 还需要针对其他哈希长度实现 Rice 解码算法。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-10。
[null,null,["最后更新时间 (UTC):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."]]