Closes the last two SerpAPI quality issues seen in prod after PR #100 merged#101
Merged
Conversation
SerpAPI's google_shopping engine occasionally cross-contaminates thumbnails between adjacent results (observed in prod: a Zara product card carrying an image.hm.com URL, a Uniqlo card carrying a static.zara.net URL). Cards rendered correctly but looked broken because the image clearly didn't represent the product. Added a per-brand image-host whitelist (e.g. Zara -> zara.net/zara.com) and reject rows whose image is hosted somewhere else. Marketplaces (Vinted, Depop, Grailed, eBay) are exempt because sellers upload arbitrary imagery. This also tends to drop category-page rows since those usually come back with mismatched or placeholder images. Existing tests updated to use brand-aligned CDN hosts; new cases cover the cross-contamination scenarios and the marketplace exemption.
SerpAPI's google_shopping engine returns two response shapes depending on the query: (a) direct retailer URLs with retailer-hosted thumbnails, or (b) Google Shopping redirect URLs (host=google.com) with thumbnails proxied through encrypted-tbn*.gstatic.com. The previous strict-host filters rejected every shape-(b) row, leaving the recommender empty for many real queries. Now: - When the product_link host is google.com (and only then), trust the `source` field as the retailer label. This stays safe — a non-Google URL with a spoofed source claim is still rejected. - Accept gstatic.com image hosts unconditionally. Google manages the proxy and assigns the image, so we treat it as trusted-by-source. Verified live against SerpAPI with 5 realistic queries — 15 accepted recommendations, all with brand/name/price/image consistent. Tests cover the redirect path, the spoofed-source attack, and the gstatic image exemption.
…ring sanitization' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
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.
Wrong-product images — SerpAPI sometimes returns a thumbnail from a neighboring shopping
row (e.g. a Zara card carrying an
image.hm.comURL). Now rejected by a per-brand image-CDNwhitelist (
zara.netfor Zara,static.nike.comfor Nike, etc.).Empty / $0 results from Google Shopping redirect responses — SerpAPI's google_shopping
engine returns two response shapes. The previous strict-host filter rejected every row in shape B
(where
product_linkis agoogle.comredirect and the thumbnail is proxied viagstatic.com). Now:product_linkhost isgoogle.com, trust thesourcefield as the retailer label(whitelist still applies — non-Google URLs with spoofed source claims still rejected).
gstatic.comim