📖 1 minute read
When implementing content whitelists with opt-in flags, always handle the empty whitelist case explicitly. An empty whitelist combined with a “whitelist required” flag should return NO results, not bypass the filter.
This pattern prevents accidental data leakage when a partner has whitelist requirements but hasn’t configured items yet. Match your internal reports to your API behavior – if the API returns nothing, the report should too.
if ($partner->getContentWhitelist()->isEmpty()) {
if ($partner->requiresWhitelist()) {
// Empty whitelist + requirement = return nothing
return $query->whereIn('products.id', []);
}
// No requirement, skip filtering
return $query;
}
// Has whitelist items, apply filter
return $query->whereIn(
'products.id',
$partner->getContentWhitelist()->pluck('product_id')->toArray()
);
Leave a Reply