Repository navigation
fix(billing): require authenticated session to issue invoices/payment links - #3142
Merged
Merged
Conversation
… links Closes the cross-org contamination class that produced the Triton/Encypher mix-up: an LLM-supplied or admin-typed prospect_contact_email could become the Stripe customer of record. Identity now comes from the signed-in session and the org row only — never caller input — for any tool path that issues a Stripe customer, subscription, invoice, or checkout. - create_payment_link / send_invoice / confirm_send_invoice (Addie member tools): drop caller-supplied identity fields from schemas; source email, user_id, org_id, billing_address from memberContext + org row only. create_payment_link now stamps workosUserId on the checkout session for deterministic webhook attribution. - send_payment_request (Addie admin tool): remove payment_link and send_invoice direct-issue actions. New send_invite action wraps the existing membership-invite flow — recipient signs in and pays as themselves. - POST /api/admin/accounts/:orgId/payment-link: removed (returns 410 with migration message). Sibling /prospects/:orgId/payment-link too. - Admin UI payment-link modals removed from admin-account-detail.html and admin-accounts.html; the existing membership-invite affordance is now the only path. - invite-membership routes no longer mirror the caller-supplied contact_email back onto organizations.prospect_contact_email — that was a latent re-introduction risk; the membership_invites row is the canonical record. Mirrors the same lockdown applied to the invoice direct-issue path in commit 23018ce. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced Apr 25, 2026
Concurrent intake race: two simultaneous billing intakes can both pass the duplicate-sub guard
#3179
Closed
bokelley
added a commit
that referenced
this pull request
Apr 25, 2026
* fix(billing): refuse to mint a duplicate subscription on an org Adds blockIfActiveSubscription, run by the three routes that can mint a Stripe subscription/invoice on an org's behalf: - POST /api/checkout-session - POST /api/invoice-request - POST /api/invite/:token/accept If the org's existing subscription status is active, trialing, or past_due, the route returns 409 with the existing subscription details and a Stripe Customer Portal URL. Tier upgrades and payment-method changes belong in the portal, not these intake routes. Without this guard, two of these routes in sequence produced the duplicate $3K Builder subscription on top of Triton's active $10K Corporate sub in April 2026 — the same incident that drove the issuer-identity lockdown in #3142. The lockdown closed the "wrong identity" door; this closes the "wrong number of subs" door. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * Address reviewer feedback on duplicate-subscription guard - Privilege escalation: invite route no longer returns a Stripe Customer Portal URL. The recipient gets `member` role on the org (not `admin`), and the portal session would grant admin-equivalent control over the existing subscription. Helper signature now takes BlockOptions, with customerPortalReturnUrl required to opt-in to the URL. Public routes pass the URL (member is verified upstream); the invite route omits it and the 409 message points to finance@ + dashboard instead. - Decimal formatting: render amounts with minimumFractionDigits=2 so $250.50 doesn't display as $250.5. - Reuse TIER_PRESERVING_STATUSES from organization-db.ts instead of a duplicate BLOCKING_STATUSES set — same intent, no drift risk. - Fallback message when portal URL is unavailable (org has no Stripe customer, portal creation fails, or caller suppressed it). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
2 of 4 tasks
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
Closes the cross-org contamination class that produced the Triton/Encypher mix-up (Apr 2026): an LLM-supplied or admin-typed
prospect_contact_emailcould become the Stripe customer of record. After this PR, identity for any Stripe-mutating tool path is sourced from the signed-in session and the org row only — never caller input.Mirrors the same lockdown commit
23018ce5eapplied to the invoice direct-issue path.What changed
Addie billing tools (
server/src/addie/mcp/billing-tools.ts):create_payment_link: droppedcustomer_emailfrom schema. Refuses without member context. StampsworkosUserIdon the checkout session for deterministic webhook attribution viaresolveWorkosUserForSubscription.send_invoice/confirm_send_invoice: droppedcontact_email,contact_name,company_name,billing_addressfrom schemas. Email comes frommemberContext.workos_user.email; company name and billing address from the org row.confirm_send_invoicerefuses if the org has no billing address on file.Addie admin tool (
server/src/addie/mcp/admin-tools.ts):send_payment_request: removedpayment_linkandsend_invoicedirect-issue actions. Newsend_invitewrapscreateMembershipInvite+sendMembershipInviteEmail. Recipient signs in, accepts the agreement, billing is issued in their authenticated session.Server routes:
POST /api/admin/accounts/:orgId/payment-link: returns 410 Gone (was direct-issue usingprospect_contact_email).POST /api/admin/prospects/:orgId/payment-link: same.invite-membershipno longer mirrors caller-suppliedcontact_emailback ontoorganizations.prospect_contact_email— that was the latent re-introduction surface.Admin UI:
admin-account-detail.htmlandadmin-accounts.html. The existing membership-invite affordance is now the only path.Tests:
server/tests/unit/billing-tool-lockdown.test.ts(8 tests).tests/addie/billing-tools.test.ts(20 tests, was 9 — old "fall back to AI-provided email" tests rewritten to assert refusal).Operational scripts (one-off, already executed against prod):
scripts/incidents/2026-04-triton-encypher-diagnostic.ts— read-only Stripe + admin API state dump.scripts/incidents/2026-04-triton-unwind.ts— three Stripe writes (cancel duplicate Builder sub, fix customer email/name, touch Corporate sub to fire the webhook). Already ran live; Triton's row now readsmembership_tier=company_icl,subscription.status=active,subscription.amount=$10K,[email protected].Card payment for prospects (follow-up)
Today's invite-acceptance flow ends in a Stripe-emailed invoice; the recipient pays via the Stripe-hosted invoice "Pay" button (4 clicks: invite → sign-in → invoice → pay). For tighter card UX we could extend
POST /api/invite/:token/acceptwithpayment_method: 'card' | 'invoice'and mint a Checkout session in the recipient's session for the card branch. Filing as a follow-up — not required to close the bug class.The adtech-product-expert reviewer also flagged a real edge case: enterprise PO buyers where finance/AP signs the check but never logs in. Today's invite path forces auth on the payer. Filing as a follow-up — keep the lockdown invariant (record-of-truth comes from authenticated identity) and add
draft_invoice→send_invoice_to_billing_emailonce the primary contact has accepted the invite.Test plan
npm run typecheck— cleannpm run test:unit— 834/834 passingnpm run test:server-unit— 2143/2143 passing (8 new lockdown tests)pending_agreement_user_idrecords the recipientsend_invite🤖 Generated with Claude Code