Migration From V4
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Un miglioramento significativo di Google Safe Browsing v5 rispetto alla v4 (in particolare, l'API Update v4) è la freschezza e la copertura dei dati. Poiché la protezione dipende in gran parte dal database locale gestito dal client, il ritardo e le dimensioni dell'aggiornamento del database locale sono i principali fattori che contribuiscono alla mancata protezione. Nella versione 4, il client tipico impiega dai 20 ai 50 minuti per ottenere la versione più aggiornata degli elenchi di minacce. Purtroppo, gli attacchi di phishing si diffondono rapidamente: a partire dal 2021, il 60% dei siti che sferrano attacchi è attivo per meno di 10 minuti. La nostra analisi mostra che circa il 25-30% della protezione anti-phishing mancante è dovuto a questo tipo di dati obsoleti. Inoltre, alcuni dispositivi non sono attrezzati per gestire l'intera gamma di elenchi di minacce di Google Navigazione sicura, che continua a crescere nel tempo.
Se al momento utilizzi l'API Update v4, esiste un percorso di migrazione semplice dalla versione 4 alla versione 5 senza dover reimpostare o cancellare il database locale. Questa sezione descrive come farlo.
Aggiornamenti degli elenchi di conversione
A differenza di V4, in cui gli elenchi sono identificati dalla tupla di tipo di minaccia, tipo di piattaforma e tipo di voce di minaccia, in V5 gli elenchi sono identificati semplicemente per nome. Ciò offre flessibilità quando più elenchi v5 potrebbero condividere lo stesso tipo di minaccia. I tipi di piattaforma e i tipi di voci relative alle minacce vengono rimossi nella versione 5.
Nella versione 4, si utilizza il metodo threatListUpdates.fetch per scaricare gli elenchi. Nella versione 5, si passa al metodo hashLists.batchGet.
Devono essere apportate le seguenti modifiche alla richiesta:
- Rimuovi completamente l'oggetto
ClientInfo
v4. Anziché fornire l'identificazione di un client utilizzando un campo dedicato, utilizza semplicemente l'intestazione User-Agent. Sebbene non esista un formato prescritto per fornire l'identificazione del client in questa intestazione, ti suggeriamo di includere semplicemente l'ID client e la versione del client originali separati da uno spazio o da una barra.
- Per ogni oggetto
ListUpdateRequest
v4:
- Cerca il nome dell'elenco v5 corrispondente in elenchi disponibili e forniscilo nella richiesta v5.
- Rimuovi i campi non necessari, ad esempio
threat_entry_type
o platform_type
.
- Il campo
state
nella versione 4 è direttamente compatibile con il campo versions
della versione 5. La stessa stringa di byte che verrebbe inviata al server utilizzando il campo state
nella versione 4 può essere inviata semplicemente nella versione 5 utilizzando il campo versions
.
- Per i vincoli della versione 4, la versione 5 utilizza una versione semplificata chiamata
SizeConstraints
. I campi aggiuntivi, come region
, devono essere eliminati.
Alla risposta devono essere apportate le seguenti modifiche:
- L'enum
ResponseType
della v4 viene semplicemente sostituito da un campo booleano denominato partial_update
.
- Il campo
minimum_wait_duration
ora può essere zero o omesso. In caso affermativo, al client viene chiesto di effettuare immediatamente un'altra richiesta. Ciò si verifica solo quando il client specifica in SizeConstraints
un vincolo più piccolo per le dimensioni massime dell'aggiornamento rispetto alle dimensioni massime del database.
- L'algoritmo di decodifica Rice per numeri interi a 32 bit dovrà essere modificato. La differenza è che i dati codificati sono codificati con un endianness diverso. Sia nella versione 4 che nella versione 5, i prefissi hash a 32 bit sono ordinati lessicograficamente. Tuttavia, nella versione 4, questi prefissi vengono trattati come little endian durante l'ordinamento, mentre nella versione 5 vengono trattati come big endian. Ciò significa che il client non deve eseguire alcun ordinamento, poiché l'ordinamento lessicografico è identico all'ordinamento numerico con big endian. Un esempio di questo tipo nell'implementazione di v4 di Chromium è disponibile qui. Questo tipo di ordinamento può essere rimosso.
- L'algoritmo di decodifica Rice dovrà essere implementato anche per altre lunghezze hash.
Ricerca di hash di conversione
Nella versione 4, si utilizzava il metodo fullHashes.find per ottenere gli hash completi. Il metodo equivalente nella versione 5 è hashes.search.
Devono essere apportate le seguenti modifiche alla richiesta:
- Struttura il codice in modo da inviare solo prefissi hash di esattamente 4 byte di lunghezza.
- Rimuovi completamente gli oggetti
ClientInfo
v4. Anziché fornire l'identificazione di un client utilizzando un campo dedicato, utilizza semplicemente l'intestazione User-Agent. Sebbene non esista un formato prescritto per fornire l'identificazione del client in questa intestazione, ti suggeriamo di includere semplicemente l'ID client e la versione del client originali separati da uno spazio o da una barra.
- Rimuovi il campo
client_states
. Non è più necessario.
- Non è più necessario includere
threat_types
e campi simili.
Alla risposta devono essere apportate le seguenti modifiche:
- Il campo
minimum_wait_duration
è stato rimosso. Il cliente può sempre inviare una nuova richiesta in base alle necessità.
- L'oggetto
ThreatMatch
v4 è stato semplificato nell'oggetto FullHash
.
- La memorizzazione nella cache è stata semplificata in un'unica durata della cache. Consulta le procedure riportate sopra per interagire con la cache.
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-08-10 UTC.
[null,null,["Ultimo aggiornamento 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."]]