Migration From V4
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
Google セーフ ブラウジング v5 の v4(特に v4 Update API)に対する大きな改善点の 1 つは、データの鮮度とカバレッジです。保護はクライアントが維持するローカル データベースに大きく依存しているため、ローカル データベースの更新の遅延とサイズが、保護の失敗の主な原因となります。v4 では、一般的なクライアントが最新バージョンの脅威リストを取得するのに 20 ~ 50 分かかります。残念ながら、フィッシング攻撃は急速に拡大しています。2021 年の時点で、攻撃を配信するサイトの 60% は 10 分未満で消滅しています。Google の分析によると、フィッシング対策が欠落している原因の約 25 ~ 30% は、このようなデータの古さによるものです。また、一部のデバイスは、Google セーフ ブラウジングの脅威リスト全体を管理する機能を備えていません。このリストは、時間の経過とともに拡大し続けています。
現在 v4 Update API を使用している場合は、ローカル データベースをリセットまたは消去することなく、v4 から v5 へのシームレスな移行パスがあります。このセクションでは、その方法について説明します。
リストの更新を変換する
V4 ではリストは脅威タイプ、プラットフォーム タイプ、脅威エントリ タイプのタプルで識別されますが、v5 ではリストは名前で識別されます。これにより、複数の v5 リストで同じ脅威タイプを共有する場合に柔軟性が得られます。v5 では、プラットフォーム タイプと脅威エントリ タイプが削除されています。
v4 では、threatListUpdates.fetch メソッドを使用してリストをダウンロードします。v5 では、hashLists.batchGet メソッドに切り替えます。
リクエストに次の変更を加える必要があります。
- v4
ClientInfo
オブジェクトを完全に削除します。専用のフィールドを使用してクライアントの識別情報を指定する代わりに、よく知られている User-Agent ヘッダーを使用するだけです。このヘッダーでクライアント ID を指定する形式は規定されていませんが、元のクライアント ID とクライアント バージョンをスペース文字またはスラッシュ文字で区切って含めることをおすすめします。
- 各 v4
ListUpdateRequest
オブジェクトについて:
- 利用可能なリストから対応する v5 リスト名を探し、その名前を v5 リクエストで指定します。
threat_entry_type
や platform_type
などの不要なフィールドを削除します。
- v4 の
state
フィールドは、v5 の versions
フィールドと直接互換性があります。v4 の state
フィールドを使用してサーバーに送信されるバイト文字列は、v5 の versions
フィールドを使用して送信できます。
- v4 制約の場合、v5 では
SizeConstraints
という簡略版が使用されます。region
などの追加フィールドは削除する必要があります。
レスポンスに次の変更を加える必要があります。
- v4 の enum
ResponseType
は、partial_update
という名前のブール値フィールドに置き換えられます。
minimum_wait_duration
フィールドは、ゼロまたは省略できるようになりました。その場合、クライアントは直ちに別のリクエストを行うよう求められます。これは、クライアントが SizeConstraints
で、データベースの最大サイズよりも小さい最大更新サイズの制約を指定した場合にのみ発生します。
- 32 ビット整数の Rice デコード アルゴリズムを調整する必要があります。違いは、エンコードされたデータが異なるエンディアンでエンコードされていることです。v4 と v5 の両方で、32 ビットのハッシュ プレフィックスは辞書順に並べ替えられます。ただし、v4 では、これらの接頭辞は並べ替え時にリトル エンディアンとして扱われますが、v5 ではビッグ エンディアンとして扱われます。つまり、辞書式順序の並べ替えはビッグ エンディアンの数値順序の並べ替えと同じであるため、クライアント側で並べ替えを行う必要はありません。v4 の Chromium 実装におけるこの種の例は、こちらで確認できます。このような並べ替えは削除できます。
- Rice デコード アルゴリズムは、他のハッシュ長にも実装する必要があります。
ハッシュ検索の変換
v4 では、fullHashes.find メソッドを使用して完全なハッシュを取得します。v5 の同等のメソッドは the hashes.search メソッドです。
リクエストに次の変更を加える必要があります。
- コードを構造化して、長さが 4 バイトのハッシュ プレフィックスのみを送信します。
- v4
ClientInfo
オブジェクトをすべて削除します。専用のフィールドを使用してクライアントの識別情報を指定する代わりに、よく知られている User-Agent ヘッダーを使用するだけです。このヘッダーでクライアント ID を指定する形式は規定されていませんが、元のクライアント ID とクライアント バージョンをスペース文字またはスラッシュ文字で区切って含めることをおすすめします。
client_states
フィールドを削除します。不要になりました。
threat_types
などのフィールドを含める必要はなくなりました。
レスポンスに次の変更を加える必要があります。
minimum_wait_duration
フィールドが削除されました。クライアントは必要に応じていつでも新しいリクエストを発行できます。
- v4
ThreatMatch
オブジェクトが FullHash
オブジェクトに簡略化されました。
- キャッシュ保存期間が 1 つに簡素化されました。キャッシュの操作については、上記の手順をご覧ください。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-08-10 UTC。
[null,null,["最終更新日 2025-08-10 UTC。"],[],[],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."]]