feat(kilo-pass): enforce duplicate-card purchase window#3768
feat(kilo-pass): enforce duplicate-card purchase window#3768jeanduplessis wants to merge 2 commits into
Conversation
| ) | ||
| ); | ||
|
|
||
| for (const record of [...blockAudits, ...issuanceRecords]) { |
There was a problem hiding this comment.
WARNING: False-positive attribution conflict on late replay of an initial invoice
The issuanceRecords query uses OR(stripe_invoice_id = X, stripe_subscription_id = Y), which returns ALL issuances for the subscription — including issuances from later billing cycles (months 2, 3, …). The conflict loop then checks that every returned record has exactly stripeInvoiceId === params.stripeInvoiceId, stripeSubscriptionId === params.stripeSubscriptionId, and kiloUserId === params.kiloUserId. Issuances from later invoices have a different stripeInvoiceId, so they trip the conflict guard and throw — even though there is no real conflict.
Concrete scenario:
- Month-1 initial invoice is processed successfully → issuance
stripe_invoice_id = in_month1is written. - Months 2–6 are processed normally → issuances
in_month2…in_month6are written. - Stripe re-delivers the month-1 webhook (late retry / infra replay).
loadDuplicateCardReplayAuthorityis called withstripeInvoiceId = in_month1.- The
ORquery returns all 6 issuances. Months 2–6 havestripeInvoiceId !== in_month1→reportAttributionConflictthrows and invoice handling is aborted.
The function's purpose is to detect whether this specific invoice was already handled; the subscription-scoped OR branch is intended for the blocked-audit check, where a matching subscription with a different invoice genuinely indicates something went wrong. For the issuance side the intent is only to find an issuance linked to params.stripeInvoiceId. Limiting the issuance query to WHERE stripe_invoice_id = params.stripeInvoiceId (dropping the subscription OR) would correctly identify the allowed-replay case and avoid false conflicts.
Code Review SummaryStatus: 1 Issue Found | Recommendation: Address before merge Executive SummaryA false-positive attribution conflict in Overview
Issue Details (click to expand)WARNING
Files Reviewed (9 files)
Fix these issues in Kilo Cloud Reviewed by claude-4.6-sonnet-20260217 · 8,286,029 tokens Review guidance: REVIEW.md from base branch |
Summary
Blocks rapid cross-account Kilo Pass card reuse during the 24 hours after its first permanent fingerprint claim, while allowing same-user reuse and later cross-account purchases.
Why this change is needed
The previous duplicate-card gate could prevent card reuse for months while another account retained an active subscription and could run again on renewals. A rolling accepted-purchase implementation would narrow that behavior but introduce another persistent anti-abuse model alongside existing fingerprint claims and issuance history.
The intended threat model is rapid cross-account reuse shortly after a card first appears, not continuous rolling enforcement after every later purchase.
How this is addressed
Human Verification
Reviewer Notes
Human Reviewer Flags
Code Reviewer Agent
Code Reviewer Notes