ローカル データベース
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
このドキュメントは、Update API(v4)メソッド threatListUpdates.fetch に適用されます。
データベースの設定
Update API を使用するクライアントは、ローカル データベースを設定し、使用するセーフ ブラウジング リストの初期ダウンロードを行う必要があります。まず、safebrowsing
Go パッケージをビルドしてデプロイします(または、このパッケージを使用して独自の実装をモデル化します)。詳しくは、https://github.com/google/safebrowsing/ をご覧ください。
データベースの更新
最新の脅威から保護するため、クライアントは
threatListUpdates.fetch メソッドを使用してローカルのセーフ ブラウジング リストを定期的に更新することを強くおすすめします。
threatListUpdates.fetch リクエストでは、更新するリストを指定します。クライアントにメモリや帯域幅の制限がある場合は、リクエストを使用して更新の制約を設定することもできます(
更新の制約をご覧ください)。以下で説明するように、
threatListUpdates.fetch レスポンスはリストごとに完全な更新または部分更新のいずれかを返します。
フル アップデート
クライアントが threatListUpdates.fetch リクエストの state
フィールドが空のままになっている場合、またはフル アップデートが必要であるとサーバーが判断した場合には、完全な更新が返されます。完全な更新の場合は、追加のみが返されます。クライアントは、更新を適用して検証チェックを実施する前に、ローカル データベースを消去する必要があります。
空の状態
クライアントがリストの最初のリクエストを送信すると、完全な更新が返されます。この場合、指定する値がないため、リクエストの state
フィールドは空のままとなり、レスポンスの newClientState
フィールドはローカルリストの初期状態を返します。クライアントが後続のリクエストで state
フィールドを意図的に空のままにした場合も、完全な更新が返されます。これにより、完全な更新が強制的に行われ、レスポンスの newClientState
フィールドに新しい状態が返されます。
サーバーの決定
クライアントが部分的な更新のみをリクエストした場合、セーフ ブラウジング サーバーから完全な更新が返されることがあります。これは、クライアントが最初にリストの小さいバージョンをダウンロードしてから、大きいバージョンに更新する場合に発生することがあります。サーバーは単にリスト全体を含む完全な更新を返します。また、クライアントが長期間データをダウンロードしておらず、部分的な更新をリクエストした場合にも、サーバーはリスト全体を含む完全な更新を返します。
部分更新
クライアントが threatListUpdates.fetch リクエストの state
フィールドに値を指定すると、部分更新が返されます(上記の例外は、完全な更新が必要であるとサーバーが判断した場合です)。部分更新の場合は、追加と削除の両方が返されます。クライアントはローカル データベースのリストを更新し(追加前に削除を適用)、検証チェックを実行します。
追加
追加とは、ローカル データベースに追加する必要がある SHA256 ハッシュ プレフィックスです。ハッシュ プレフィックスの大部分は 4 バイトですが、一部のハッシュ プレフィックスの長さは 4 ~ 32 バイトです。したがって、複数の追加セットが返されることがあります。たとえば、1 つに 4 バイトのプレフィックスが含まれ、もう 1 つが 5 バイトのプレフィックスを含む場合などです。
クライアントが圧縮をサポートしている場合、Rice 圧縮を使用してレスポンスを圧縮できます。ただし、圧縮されるのは 4 バイトのハッシュ プレフィックスのみです。長いハッシュ プレフィックスは常に非圧縮の未加工形式で送信されます(圧縮を参照)。
削除
削除は、辞書順に並べ替えられたクライアント データベース内のゼロベースのインデックスで、ローカル データベースから削除する必要があるエントリを指します。削除のセットは 1 つだけ返されます。
クライアントが圧縮をサポートしている場合は、「rice hashes」と「rice indices」が返されます。圧縮がサポートされていない場合は、「未加工ハッシュ」と「未加工インデックス」が返されます(圧縮を参照)。
検証結果
threatListUpdates.fetch レスポンスが完全な更新または部分更新で返されると、クライアントは検証チェックを行うことが想定されます。
クライアントはまずローカル データベースのリストを更新します(追加する前に削除を適用します)。クライアントは、(辞書順に並べ替えられた)ローカルリストの SHA256 ハッシュを計算し、レスポンスで返されたチェックサムと比較します。2 つの値が同じであれば、セーフ ブラウジング リストは「正しい」と見なされます。
2 つの値が等しくない場合、セーフ ブラウジング リストは「破損」していると見なされます。クライアントはデータベースからリストを消去し、state
フィールドを空の文字列に設定して 2 回目の更新を再発行する必要があります。これにより、完全な更新が強制的に行われ、まったく新しいリストと状態が返されます。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-07-25 UTC。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-07-25 UTC。"],[[["\u003cp\u003eThe Safe Browsing Update API (v4) allows clients to download and update local Safe Browsing lists for threat detection.\u003c/p\u003e\n"],["\u003cp\u003eClients need to set up a local database and perform an initial download of the desired Safe Browsing lists.\u003c/p\u003e\n"],["\u003cp\u003eRegular updates are crucial, and can be either full (requiring a local database clear) or partial (applying additions and removals).\u003c/p\u003e\n"],["\u003cp\u003eValidation checks using SHA256 hashes ensure the integrity of the local Safe Browsing lists after each update.\u003c/p\u003e\n"],["\u003cp\u003eIf validation fails, clients should clear the local list and request a full update to obtain a fresh copy.\u003c/p\u003e\n"]]],["Clients utilizing the Update API must establish a local database and download Safe Browsing lists. Regular updates are crucial via the `threatListUpdates.fetch` method, specifying desired lists and update constraints. The server responds with either full updates (client clears database and applies additions) or partial updates (client applies removals before additions). After each update, the local database's SHA256 hash is validated against the response checksum; mismatches trigger a full update.\n"],null,["# Local Databases\n\nThis document applies to the following method:\n[Update API (v4)](/safe-browsing/v4/update-api):\n[threatListUpdates.fetch](/safe-browsing/v4/update-api#example-threatListUpdatesfetch).\n\nDatabase setup\n--------------\n\nClients using the Update API are required to set up a local database and to perform an initial\ndownload of the Safe Browsing lists they want to work with. To get going, you can build and deploy\nthe `safebrowsing` Go package (or use the package to model your own implementation). For more information\nsee \u003chttps://github.com/google/safebrowsing/\u003e.\n\nDatabase updates\n----------------\n\nTo ensure protection against the latest threats, clients are strongly encouraged to regularly update their local Safe Browsing lists using the [threatListUpdates.fetch](/safe-browsing/reference/rest/v4/threatListUpdates/fetch) method. The [threatListUpdates.fetch request](/safe-browsing/v4/update-api#http-post-request) specifies the lists to be updated. If clients have memory or bandwidth limitations, they can also use the request to set update constraints (see [Update Constraints](/safe-browsing/v4/update-constraints)). The [threatListUpdates.fetch response](/safe-browsing/v4/update-api#http-post-response) returns either a full update or partial update for each list, as explained below.\n\n\u003cbr /\u003e\n\n### Full updates\n\nFull updates are returned when the client leaves the `state` field in the\n[threatListUpdates.fetch request](/safe-browsing/v4/update-api#http-post-request)\nempty or when the server determines a full update is required. For full updates, only\n[additions](/safe-browsing/v4/local-databases#additions) are returned. The client is\nexpected to *clear the local database* before applying the updates and performing the\n[validation check](/safe-browsing/v4/local-databases#validation-checks).\n**Empty state**\n\nFull updates are returned when the client sends the initial request for a list. In this case, the\n`state` field in the request is left empty (because there is no value to provide) and the `newClientState`\nfield in the response returns the initial state for the local list. Full updates are also returned\nwhen the client purposely leaves the `state` field empty on subsequent requests. This will force a full\nupdate and return a new state in the `newClientState` field of the response.\n**Server decision**\n\nOccasionally, the Safe Browsing server returns a full update when only a partial update\nwas requested by the client. This may happen when the client initially downloads a small version of the list\nand then updates to a larger version of the list; the server will simply return a full update with\nthe entire list. This may also happen if the client hasn't downloaded data in a long time and requests\na partial update; again, the server will simply return a full update with the entire list.\n\n### Partial updates\n\nPartial updates are returned when the client supplies a value for the `state` field in the\n[threatListUpdates.fetch request](/safe-browsing/v4/update-api#http-post-request)\n(the exception, as noted above, is when the server determines a full update is required). For\npartial updates, both [additions](/safe-browsing/v4/local-databases#additions) and\n[removals](/safe-browsing/v4/local-databases#removals) are returned. The client updates\nthe lists in the local database (applying the removals before the additions) and then performs the\n[validation check](/safe-browsing/v4/local-databases#validation-checks).\n\n### Additions\n\nAdditions are SHA256 hash prefixes that should be added to the local database. The vast majority\nof hash prefixes are 4 bytes long but some hash prefixes may have any length between 4 and 32 bytes.\nTherefore, multiple sets of additions could be returned; for example, one containing the 4-byte prefixes\nand one containing 5-byte prefixes.\n\nIf the client supports compression, the response may be compressed using Rice compression. However,\nonly 4-byte hash prefixes get compressed. Longer hash prefixes are always sent in uncompressed, raw\nformat (see [Compression](/safe-browsing/v4/compression)).\n\n### Removals\n\nRemovals are zero-based indices in the lexicographically-sorted client database pointing at entries\nthat should be removed from the local database. Only one set of removals will be returned.\n\nIf the client supports compression, \"rice hashes\" and \"rice indices\" are returned. If compression\nis not supported, \"raw hashes\" and \"raw indices\" are returned (see\n[Compression](/safe-browsing/v4/compression)).\n\nValidation checks\n-----------------\n\nWhen the [threatListUpdates.fetch response](/safe-browsing/v4/update-api#http-post-response)\nis returned---with either a full update or a partial update---the client is expected to perform a\nvalidation check.\n\nThe client first updates the lists in the local database (applying the removals before the\nadditions). The client then computes the SHA256 hash of the\n(lexicographically sorted) local list and compares it to the checksum returned in the response.\nIf the two values are equal, the Safe Browsing list is considered \"correct.\"\n\nIf the two values are not equal, the Safe Browsing list is considered \"corrupt.\" The client must\nclear the list from the database and reissue a second update with the `state` field set\nto the empty string; this will force a full update and return a brand new list and state."]]