Skip to content

Entitlement reconciliation: bind Stripe to workos_user_id, surface link flow at signup + access-block #3589

Closed as not planned
1 of 3 issues completed

Description

@bokelley

Triggering incident

A person signed up to AAO twice — once with a work email (paid for Professional, subscription active on org A), once with [email protected] (personal workspace, no subscription). The two WorkOS users were never linked. When they tried to start the S2 Creative Specialist exam logged in as gmail, the system blocked them with "membership required." Resolved manually via admin org-merge.

This is not a one-off. The system has no path from "this WorkOS user" to "any org this person paid through." Same gap will fire again the next time someone has work + personal emails.

Why this is the right place to fix it

Expert review (adtech-product-expert) was unambiguous: do not solve entitlements with a person-level identity primitive. Adtech precedent (TTD, DV360, GAM) runs entitlements as seats granted to login identities, scoped to an account. WorkOS already models this — we just aren't using it. A person-as-entitlement primitive breaks B2B (consultants in two member orgs inherit both, seat counts become uncountable, leavers keep entitlements).

The relationship/Addie identity work is a separate track (see companion issue, to be filed).

Scope

Three independent changes, shippable separately:

1. Stripe checkout binds to workos_user_id (security fix)

Today handle-subscription-created resolves customer email → org, which is buyer-controllable (security review flagged this as HIGH severity — attacker can redirect a victim's subscription via crafted checkout email).

  • Set client_reference_id (or metadata.workos_user_id) server-side at checkout-session creation
  • Webhook attaches subscription to the org of that WorkOS user, not to a fuzzy-resolved customer email
  • Email-based resolution becomes advisory only — surfaced for admin review, never moves money or entitlements automatically

Files: server/src/billing/handle-subscription-created.ts, server/src/billing/stripe-client.ts (checkout-session creation)

2. Signup detects existing paying org for the email's domain

When a new WorkOS user signs up and there's an active-subscription org with a matching email_domain, prompt: "We found a paid membership for [domain]. Request to join, or continue with a personal workspace?"

This is a static auth-flow screen, not an Addie conversation (identity is a security boundary; LLMs don't belong in security boundaries — agentic-product-architect was firm on this).

Files: signup flow, WorkOS organization invite API

3. Surface user-initiated email link at access-block time

When entitlement check fails on a personal workspace, the response includes "Have another email associated with a paid membership?" link → existing email-link-token flow (substrate exists at server/src/db/migrations/334_email_link_tokens.sql).

User authenticates session A, requests link, system sends signed challenge to email B; user confirms while authenticated as B → both WorkOS users joined to the paying org via WorkOS invite. Proof-of-control on both sides; no fuzzy auto-merge anywhere in the path.

Files: server/src/addie/mcp/certification-tools.ts:35 (membershipRequiredMessage), server/src/middleware/auth.ts (link-token verification)

Out of scope

  • Building a persons table — that's the relationship-model track, separate issue
  • Auto-merge of any kind — security review identified multiple HIGH-severity attack paths in fuzzy auto-merge; all merges are user-initiated with proof of control on both identities
  • Consolidating credentials across WorkOS users — credentials stay bound to the originating workos_user_id

Done state

  • Stripe webhook test: subscription with attacker-controlled customer email cannot redirect to victim's org
  • Signup test: user with email at domain.com matching an active-subscription org sees the join-existing-org prompt
  • Access-block test: user blocked at start_certification_exam on personal workspace can initiate link-to-other-email and complete it without admin involvement
  • Tom-class incidents drop to zero in escalations

References

Sub-issues

Sub-issues

1 of 3 Issues completed
Loading 3 sub-issues

Activity

  1. added
    addie
    member-tools
    claude-triaging
    on Apr 30, 2026
  2. bokelley commented on Apr 30, 2026

    @bokelley
    ContributorAuthor

    Triage

    Classification: Bug (security) + Feature request
    Bucket(s): security-sensitive, admin / ops tools, addie
    Status: ready-for-human

    What the experts said:

    • security-reviewer: §1 approach validated — checkout already stamps workos_user_id into subscription metadata server-side; concern: createAndSendInvoice (admin-invoice path) stamps workos_organization_id but not workos_user_id, so invoice-billed orgs still fall through to email fallback after §1 ships. §3 confirm handler must implement an explicit target_email check against the authenticated session-B identity and an atomic UPDATE WHERE status='pending' to prevent TOCTOU and replay.
    • internal-tools-strategist: §1 must ship first — §2/§3 are cosmetic until the webhook attribution gap is closed. §3 is underbuilt: membershipRequiredMessage is an LLM prompt string, not a UI affordance; the merge flow needs scaffolding (Addie tool/deep-link, entitlement re-evaluation) that isn't in the spec. Minimum safe §3: plain "sign in with a different email" redirect rather than inline merge.
    • adtech-product-expert: §1 validated. §3 blocked — two WorkOS users joining the same org = two seats consumed, creating a phantom-seat billing integrity gap. Without an alias_of_workos_user_id FK on organization_memberships, §3 builds the person-as-entitlement primitive the issue explicitly rules out, just spelled differently.

    My take: §1 is the load-bearing change and is safe to execute once the invoice-path gap is resolved; §3 cannot ship as specified without a seat-alias primitive, and experts flagged this as a blocker on the current spec.

    @bokelley, your calls:

    1. Does §1 extend to createAndSendInvoice (still falls to email lookup), or is the invoice path a separate follow-up?
    2. Should §2 be scoped as a compatible extension of Direct-link join flow with payment chooser (replace per-invite tokens) #3173's signup surface rather than a parallel join-confirmation flow?
    3. Does §3 need an alias_of_workos_user_id column on organization_memberships in scope here, or does it move to the persons-table track?

    Triaged by Claude Code. Session: https://claude.ai/code/cse_01KKJebzZ2JMxWgWqRyeEcfg


    Generated by Claude Code

  3. added
    claude-triaged
    and removed
    claude-triaging
    on Apr 30, 2026
  4. added this to the Evergreen milestone on May 17, 2026
  5. bokelley commented on Aug 13, 2026

    @bokelley
    ContributorAuthor

    Split entitlement reconciliation into:

    These have different trust boundaries and should not ship as one change.

  6. added
    triage:archive-review
    on Sep 21, 2026
  7. bokelley commented on Sep 21, 2026

    @bokelley
    ContributorAuthor

    Closing this decomposed identity/billing umbrella. Attribution, verified organization join, and safe account recovery are tracked in #6492–#6494.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    addieclaude-triagedmember-toolstriage:archive-review

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions