Repository navigation
Description
Summary
Maple caches the billing service third-party JWT in sessionStorage as maple_billing_token. That token is Maple/billing-server state, not OpenSecret SDK state, so the OpenSecret SDK should not know about it or clear it. Maple needs to clear or scope this token whenever the current OpenSecret user identity changes.
Right now the token is stored under a single unscoped key and reused until the billing API rejects it. If the OpenSecret auth identity changes while a still-valid billing token remains in the tab, billing calls can be authorized as the previous user while the UI reads email/profile state from the current user.
Suspected ordering
A plausible ordering that can produce incorrect checkout ownership:
- A browser tab has a valid cached
maple_billing_tokenfor User A. - The OpenSecret auth tokens in
localStoragechange to User B through login/OAuth/deep-link/native auth or another auth transition. - The cached billing token remains in
sessionStoragebecause it is not tied to the OpenSecret user id. - The pricing page builds checkout request data from current UI auth state for User B.
BillingServicereuses the stale billing JWT for User A.- Billing server keys checkout/customer creation by the JWT subject, so checkout is created under User A while request body fields came from User B.
This is especially risky around selected-plan auto-checkout flows because checkout can be triggered immediately after auth/navigation.
Code paths to audit
frontend/src/billing/billingService.tsstoresmaple_billing_tokenas one globalsessionStoragekey and reuses it until rejected.frontend/src/components/DeepLinkHandler.tsxwrites new OpenSecret auth tokens and reloads without clearing Maple billing state.- Some signout paths call
os.signOut()directly. Since the OpenSecret SDK should not know about Maple billing state, those Maple UI paths should clear billing state themselves before/after signout. /loginand/signupalready-logged-in redirect effects can navigate to/pricing?selected_plan=...without clearing or validating the cached billing token for the current user.- Billing React Query keys such as
["billingStatus"]are not scoped by current user id.
Expected behavior
Maple should guarantee that billing requests use a billing JWT for the current OpenSecret user, or generate a fresh one before making the request.
Suggested fix
- Make billing token ownership explicit in Maple, not the OpenSecret SDK.
- Clear
maple_billing_tokenwheneveros.auth.user?.user.idchanges or auth becomes logged out. - Consider storing the billing token under a user-scoped key, or decode/check the token
subbefore reuse. - Clear billing token in Maple-owned auth transition paths, including deep-link/native auth and signout UI paths.
- Scope billing query keys by user id, for example
["billingStatus", userId]. - Prevent selected-plan auto-checkout from running until billing token state has been validated/refreshed for the current user.
No customer identifiers or production-specific data are included here because this repo is public.
Activity
AnthonyRonning commentedon Jul 11, 2026
Follow-up from validating CodeRabbit feedback on PR #607:
This is confirmed as the same pre-existing issue, not an Agent Mode regression.
History and current trigger
maple_billing_tokencache infrontend/src/billing/billingService.tsdates back to the initial Maple commit (a8df346c, January 2025).masterversion offrontend/src/components/DeepLinkHandler.tsxstill replaces OpenSecret access/refresh tokens and reloads without clearing the billing token.sessionStoragesurvives that same-WebView reload.TeamSeatMismatchAlertis mounted globally and queries billing/team state as soon as a user is authenticated, somastercan already consume a still-valid previous-account token without waiting for checkout.executeWithTokennever reaches its regenerate-on-auth-error path. The third-party JWT is account-bearing viasuband currently lives for about one hour.PR #607 touched adjacent billing lifecycle code by refreshing the singleton's OpenSecret context and adding another sidebar billing-status query. That made the invariant visible to CodeRabbit, but it did not introduce the unscoped token or deep-link path. This should remain a separate fix for this issue.
Recommended robust fix
Rather than adding more clearing calls alone:
{ userId, token }instead of a raw token.os.auth.user?.user.idto match the stored owner. Delete mismatched, signed-out, malformed, and legacy raw values.updateOpenSecretobserves an identity change or logout, while preserving it for same-user context refreshes.Focused tests
This keeps the fix in Maple, where the billing token is owned, without coupling the OpenSecret SDK to Maple-specific billing state.