feat(security): mandatory server-side receipt validation before subscription grant#724
Merged
RUKAYAT-CODER merged 3 commits intoJun 28, 2026
Conversation
…ription grant Client-side receipt acceptance allowed receipt replay, fake purchase injection (Freedom/iAP Cracker), and tampered purchase responses. All IAP receipts now POST to /api/payments/validate-receipt before any local state is updated. Subscription tier and finishTransaction are only reached on server valid:true. Network failures retry up to 3 times (exponential back-off 1s/2s/4s) before surfacing an error; non-network server errors fail immediately without retry. A receiptValidationPending guard prevents duplicate in-flight submissions.
|
@No-bodyq Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
…nto security/server-receipt-validation
Contributor
|
Kindly resolve conflict |
Contributor
Author
|
resolved |
Contributor
|
Thank you for contributing to the project. |
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.
Summary
validateReceiptthat returned{ valid: true }on any error — receipts are now never accepted client-sidevalidateReceiptnow POSTs to/api/payments/validate-receipt; retries up to 3 times (4 total attempts) on network-level failures with exponential back-off (1 s, 2 s, 4 s); throws immediately on server-returned errors (4xx / 5xx) without retrying so a rejected receipt is not retriedpurchaseUpdatedListenerininitialize()now guards entry withreceiptValidationPendingto prevent duplicate in-flight submissions; callsfinishTransactionandsetSubscriptionTieronly inside theresult.valid === truebranch; clears the pending flag in afinallyblock regardless of outcomesubscriptionTierandreceiptValidationPendingtouseAppStore(src/store/index.ts);logoutresets both;_setTiernow updates the store in addition to AsyncStorage so subscription state is reactivevalid: falserejection, retry-then-succeed on transient network error, exhausted retries throwing, server error failing immediately without retry, pending flag lifecycle,finishTransactionnot called on rejection or network failure, duplicate guard, missing-receipt guarddocs/payments/receipt-validation-flow.mdwith flow diagram, key guarantees table, full API request/response contract, and notes on restore behaviourType of Change
Testing Done
Security Considerations
productId; no receipt data, tokens, or response bodies are loggedPerformance Considerations
useCallback,useMemo) used appropriately to prevent unnecessary renders? — N/A to this changeFlatListoptimized (e.g., usinggetItemLayout,keyExtractor)? — N/A to this changeuseEffectcleanup to avoid memory leaks)? —receiptValidationPendingis always cleared infinally; no dangling promises or unhandled rejectionsChecklist
docs/payments/receipt-validation-flow.mdcreated with full flow diagram and API contractCloses #585