safebrowser: split fullHashes.find requests to respect the 500 hash prefix limit - #161
Draft
rootkiller6788 wants to merge 1 commit into
Draft
safebrowser: split fullHashes.find requests to respect the 500 hash prefix limit#161rootkiller6788 wants to merge 1 commit into
rootkiller6788 wants to merge 1 commit into
Conversation
…refix limit LookupURLsContext previously sent every unsure hash prefix in a single fullHashes.find request. The Safe Browsing API only accepts 500 hash prefixes per request and rejects larger requests with a 400 error. Split the threat entries into batches of at most maxHashPrefixesPerRequest and issue one API call per batch, merging the matches from each response. Fixes google#88.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #88.
The Safe Browsing API limits a single fullHashes.find request to 500 hash prefixes and rejects larger requests with a 400 error (see https://developers.google.com/safe-browsing/v4/update-api). Today,
LookupURLsContextcollects every "unsure" partial hash prefix into oneFindFullHashesRequest, so querying more than 500 prefixes at once fails outright.This change splits the collected threat entries into chunks of at most
maxHashPrefixesPerRequest(500), issues one API call per chunk, and merges the matches from every response before returning them to the caller. The cache is still updated per request so negative cache TTLs cover every queried prefix.Changes:
safebrowser.go: addmaxHashPrefixesPerRequestand batch thefullHashes.findcalls inLookupURLsContext.safebrowser_lookup_test.go: addTestLookupURLsHashLookupBatching, which feeds the client enough URLs to exceed the limit, asserts each API request stays within the limit, that every prefix is still queried exactly once across all requests, and that matches returned from different requests are all surfaced.go build ./...,go vet ./..., andgo test ./...pass.