When clients choose to use Google Safe Browsing v5 in the no-storage real-time mode, the client need not maintain any persistent local database. However, the client is still expected to maintain a local cache. Such a local cache need not be in persistent storage and may be cleared in case of memory pressure.
Whenever the client wishes to check a particular URL, the client always connects to the server to perform a check. This mode is similar to what clients of the v4 Lookup API may implement.
Compared to the Real-Time Mode, this mode may use more network bandwidth but may be more suitable if it is inconvenient for the client to maintain persistent local state.
The Real-Time URL Check Procedure Without a Local Database
This procedure takes a single URL u and returns SAFE or UNSAFE.
- Let
expressionsbe a list of suffix/prefix expressions generated by the URLu. - Let
expressionHashesbe a list, where the elements are SHA256 hashes of each expression inexpressions. - Let
expressionHashPrefixesbe a list, where the elements are the first 4 bytes of each hash inexpressionHashes. - For each
expressionHashPrefixofexpressionHashPrefixes:- Look up
expressionHashPrefixin the local cache. - If the cached entry is found:
- Determine whether the current time is greater than its expiration time.
- If it is greater:
- Remove the found cached entry from the local cache.
- Continue with the loop.
- If it is not greater:
- Remove this particular
expressionHashPrefixfromexpressionHashPrefixes. - Check whether the corresponding full hash within
expressionHashesis found in the cached entry. - If found, return
UNSAFE. - If not found, continue with the loop.
- Remove this particular
- If the cached entry is not found, continue with the loop.
- Look up
- Send
expressionHashPrefixesto the Google Safe Browsing v5 server using RPC SearchHashes or the REST method hashes.search. If an error occurred (including network errors, HTTP errors, etc), returnSAFE. Otherwise, let response be theresponsereceived from the SB server, which is a list of full hashes together with some auxiliary information identifying the nature of the threat (social engineering, malware, etc), as well as the cache expiration timeexpiration. - For each
fullHashofresponse:- Insert
fullHashinto the local cache, together withexpiration.
- Insert
- For each
fullHashofresponse:- Let
isFoundbe the result of findingfullHashinexpressionHashes. - If
isFoundis False, continue with the loop. - If
isFoundis True, returnUNSAFE.
- Let
- Return
SAFE.
Just like the Real-Time Mode, this procedure does not specify exactly how to send the hash prefixes to the server. For example, it is acceptable for the client to send all the expressionHashPrefixes in a single request, and it is also acceptable for the client to send each individual prefix in expressionHashPrefixes to the server in separate requests (perhaps proceeding in parallel). It is also acceptable for the client to send unrelated or randomly generated hash prefixes together with the hash prefixes in expressionHashPrefixes, as long as the number of hash prefixes sent in a single request does not exceed 30.