[PR #6950] [MERGED] fix(stripe): prevent trial abuse by checking all user subscriptions #15231

Closed
opened 2026-04-13 09:54:10 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6950
Author: @GautamBytes
Created: 12/23/2025
Status: Merged
Merged: 12/30/2025
Merged by: @himself65

Base: canaryHead: fix/stripe-trial-logic


📝 Commits (7)

  • ac7d9a4 fix(stripe): ensure trial check queries full subscription history
  • 419bbca test(stripe): improve regression test to be deterministic with decoy subscription
  • 5f74311 feat: add Paystack plugin to community plugins list (#6782)
  • 1e2197b test: update test case to cover actual issue
  • f531a4d Merge branch 'canary' into fix/stripe-trial-logic
  • 8767696 Merge branch 'canary' into fix/stripe-trial-logic
  • db89b69 Merge branch 'canary' into fix/stripe-trial-logic

📊 Changes

2 files changed (+86 additions, -1 deletions)

View changed files

📝 packages/stripe/src/routes.ts (+7 -1)
📝 packages/stripe/src/stripe.test.ts (+79 -0)

📄 Description

Description

Fixes #6863

The Issue:
Previously, the hasEverTrialed check relied on the subscriptions variable, which in some flows (like upgrading/updating) was optimized to contain only a single record (subscriptionToUpdate). This meant that if a user canceled a previous trial and started a new subscription, the check would only see the new "incomplete" record, fail to find past trial history, and grant a new trial.

The Fix:
I decoupled the trial history check from the update logic. The code now explicitly executes a findMany query to fetch all subscriptions associated with the referenceId (User ID). This ensures that hasEverTrialed validates the user's entire history, regardless of which specific subscription is currently being processed.


Summary by cubic

Prevent trial abuse by checking a user's full subscription history when upgrading or creating Stripe subscriptions. We now query all subscriptions for the user before granting any trial.

  • Bug Fixes
    • Fetch all subscriptions by referenceId via adapter.findMany and compute hasEverTrialed across any plan.
    • Decoupled the trial check from the update flow so it no longer relies on a possibly partial subscriptions array.
    • Added a test to ensure a canceled past trial blocks new trials even when an incomplete subscription exists.

Written for commit db89b695cc. Summary will update automatically on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/6950 **Author:** [@GautamBytes](https://github.com/GautamBytes) **Created:** 12/23/2025 **Status:** ✅ Merged **Merged:** 12/30/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/stripe-trial-logic` --- ### 📝 Commits (7) - [`ac7d9a4`](https://github.com/better-auth/better-auth/commit/ac7d9a43e5d361db39bf832b285fe6307ccd9902) fix(stripe): ensure trial check queries full subscription history - [`419bbca`](https://github.com/better-auth/better-auth/commit/419bbca33b034948678ae5a98fbf53ca56d81637) test(stripe): improve regression test to be deterministic with decoy subscription - [`5f74311`](https://github.com/better-auth/better-auth/commit/5f743118c52fb1809922eae3130cee334f78e3a0) feat: add Paystack plugin to community plugins list (#6782) - [`1e2197b`](https://github.com/better-auth/better-auth/commit/1e2197b3b4d3109e0b07f3190f92e3ba4a043b3e) test: update test case to cover actual issue - [`f531a4d`](https://github.com/better-auth/better-auth/commit/f531a4dd93b673cc3a3de5a019245f1a8770bde3) Merge branch 'canary' into fix/stripe-trial-logic - [`8767696`](https://github.com/better-auth/better-auth/commit/8767696992d14b225d4d25b79f2f8887d0461e47) Merge branch 'canary' into fix/stripe-trial-logic - [`db89b69`](https://github.com/better-auth/better-auth/commit/db89b695ccb2d35108150594756bf41571b1e2bd) Merge branch 'canary' into fix/stripe-trial-logic ### 📊 Changes **2 files changed** (+86 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/stripe/src/routes.ts` (+7 -1) 📝 `packages/stripe/src/stripe.test.ts` (+79 -0) </details> ### 📄 Description ### Description Fixes #6863 **The Issue:** Previously, the `hasEverTrialed` check relied on the `subscriptions` variable, which in some flows (like upgrading/updating) was optimized to contain only a single record (`subscriptionToUpdate`). This meant that if a user canceled a previous trial and started a new subscription, the check would only see the new "incomplete" record, fail to find past trial history, and grant a new trial. **The Fix:** I decoupled the trial history check from the update logic. The code now explicitly executes a `findMany` query to fetch **all** subscriptions associated with the `referenceId` (User ID). This ensures that `hasEverTrialed` validates the user's entire history, regardless of which specific subscription is currently being processed. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Prevent trial abuse by checking a user's full subscription history when upgrading or creating Stripe subscriptions. We now query all subscriptions for the user before granting any trial. - **Bug Fixes** - Fetch all subscriptions by referenceId via adapter.findMany and compute hasEverTrialed across any plan. - Decoupled the trial check from the update flow so it no longer relies on a possibly partial subscriptions array. - Added a test to ensure a canceled past trial blocks new trials even when an incomplete subscription exists. <sup>Written for commit db89b695ccb2d35108150594756bf41571b1e2bd. Summary will update automatically on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-13 09:54:10 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#15231