fix(entitlements): never let promo redemption throw into the grant response - #115
Merged
Conversation
…sponse #110 dropped the try/catch around recordPromoRedemption to make the duplicate guard atomic. Both callers grant the entitlement BEFORE recording the redemption and neither handles errors: - app/api/payments/status/route.ts:58 - app/api/payments/create-checkout/route.ts:59 So a transient DB failure in the INSERT now 500s a response that has already granted the purchase — and the status route's payload carries grant.apiKeyPlaintext, which is shown exactly once. The user would lose their API key to that 500. Restore the catch (log + return false) while keeping the atomic INSERT OR IGNORE guard and the capped increment. The recorded flag is tracked outside the try so a failed counter bump still reports the redemption row that did land. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
vu1nz Security Review0 finding(s) in PR #? No security issues found. |
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.
Follow-up to #110.
#110 made the promo duplicate guard atomic (
INSERT OR IGNORE+rowsAffected) — good — but in doing so it dropped thetry/catchthat used to wrap those queries.Both callers grant the entitlement before recording the redemption, and neither has its own error handling:
apps/web/app/api/payments/status/route.ts:58apps/web/app/api/payments/create-checkout/route.ts:59So a transient DB failure in the INSERT now throws out of
recordPromoRedemptionand 500s a response that has already granted the purchase. In the status route that response carriesgrant.apiKeyPlaintext, which the code notes is "shown exactly once" — the user would lose their API key to the 500.Change
Restore the catch (log + return
false) while keeping #110's atomic guard and capped increment intact. Therecordedflag is tracked outside thetryso a failed counter bump still reports the redemption row that did land, rather than claiming it never happened.Verification
pnpm typecheckcleanpnpm test— 99 passed (2 new)🤖 Generated with Claude Code