Skip to content

safebrowser: split fullHashes.find requests to respect the 500 hash prefix limit - #161

Draft
rootkiller6788 wants to merge 1 commit into
google:masterfrom
rootkiller6788:batch-hashlookup-requests
Draft

safebrowser: split fullHashes.find requests to respect the 500 hash prefix limit#161
rootkiller6788 wants to merge 1 commit into
google:masterfrom
rootkiller6788:batch-hashlookup-requests

Conversation

@rootkiller6788

Copy link
Copy Markdown

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, LookupURLsContext collects every "unsure" partial hash prefix into one FindFullHashesRequest, 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: add maxHashPrefixesPerRequest and batch the fullHashes.find calls in LookupURLsContext.
  • safebrowser_lookup_test.go: add TestLookupURLsHashLookupBatching, 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 ./..., and go test ./... pass.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

client should make multiple requests when >500 hash prefixes are queried

1 participant