fix(billing): deny entitlement for a feature with no products - #1858
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughSummary by CodeRabbit
Walkthrough
ChangesEntitlement check
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
rohilsurana
marked this pull request as ready for review
August 6, 2026 11:56
AmanGIT07
approved these changes
Aug 6, 2026
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.
What
CheckFeatureEntitlementwrongly returnstruefor a feature that is attached to no product.entitlement.Service.CheckdoesproductService.List(Filter{ProductIDs: feature.ProductIDs}), and whenfeature.ProductIDsis empty the store treats the empty id filter as no filter (billing_plan…billing_product_repository.go:if len(flt.ProductIDs) > 0), so it returns every product. The plan-bound product is in that list, itsplan_idsmatches an active subscription, andCheckgrants the feature to any active subscriber.Why it matters
A feature ends up with empty
ProductIDswhenever it is removed from its last product — the exact effect ofRemoveFeatureFromProduct(called byupdateProductFeatureswhen a product update drops a feature). So retiring a feature would silently leave every subscriber entitled to it. This is an over-grant (grants access it should deny), independent of the reconcile/Stripe path.Fix
Guard in
Check: a feature attached to no product cannot belong to any plan, so returnfalsebefore the list call.The fix lives in
Check, not in the store's empty-filter behaviour, because other callers rely on "empty filter = all products".Test
Added
TestService_Check_FeatureWithNoProducts: an active subscriber, a feature with emptyProductIDs. It assertsCheckreturnsfalseand leaves theProductService.Listmock unset, so the test fails ifCheckever callsListagain (a regression guard). Verified it fails without the guard (the mock rejects the unexpectedListcall) and passes with it.How it was found
Surfaced while testing the BillingProduct reconcile feature-remove flow in a local sandbox: after detaching a feature,
GetPlancorrectly dropped it, but the entitlement check kept returningtrue.