Skip to content

fix(server): prospect domain conflict no longer transfers ownership (#4321) - #4323

Merged
bokelley merged 1 commit into
mainfrom
bokelley/4321-prospect-on-conflict
May 10, 2026
Merged

bokelley merged 1 commit into
mainfrom
bokelley/4321-prospect-on-conflict

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Summary

Closes the medium finding in #4321.

Before #4159 Stage 2, organization_domains.is_primary only drove org-membership inference; after Stage 2 it also drives brand identity. The ON CONFLICT (domain) DO UPDATE in createProspect was rewriting workos_organization_id and is_primary=true on conflict — silently transferring brand identity from the original owner to a fresh prospect org.

Switch to ON CONFLICT (domain) DO NOTHING and log when the existing row is owned by a different workos_organization_id.

Two layers of defense

  1. Pre-check at resolveOrgByDomain — already rejects callers whose domain is already linked. This is the path users hit in normal operation.
  2. INSERT-level ON CONFLICT DO NOTHING (this PR) — catches races and alias-resolution misses where the pre-check returns null but the unique constraint still fires.

Out of scope

The two Low findings from #4321 (admin-side is_primary=true inserts in admin/domains.ts / organization-bootstrap.ts from non-WorkOS sources, and the FOR UPDATE serialization comment correction in me-organization-domains.ts) are not addressed here. The first is admin-trust scope; the second is a comment fix. Will track separately if they need action.

Test plan

  • New tests/integration/prospect-domain-conflict.test.ts — 3 cases:
    • Pre-check rejects when domain is already linked.
    • INSERT-level conflict (race / resolver-miss) does NOT transfer ownership.
    • Fresh-domain insert still works.
  • Sibling tests still pass: prospect-triage-function, claim-prospect-org, find-claimable-prospect-org (20/20).
  • Typecheck clean.

🤖 Generated with Claude Code

…4321)

Before #4159 Stage 2, organization_domains.is_primary only drove
org-membership inference; after Stage 2 it also drives brand identity.
The ON CONFLICT (domain) DO UPDATE in createProspect was rewriting
workos_organization_id and is_primary=true on conflict — silently
transferring brand identity from the original owner to a fresh prospect
org.

Switch to ON CONFLICT (domain) DO NOTHING and log when the existing row
is owned by a different workos_organization_id. The pre-check at
resolveOrgByDomain catches the user-visible case; this guard catches
races and alias-resolution misses where the pre-check returns null but
the unique constraint still fires.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
isLushaConfigured: () => false,
}));

import { initializeDatabase, closeDatabase, getPool } from '../../src/db/client.js';
@bokelley
bokelley merged commit a564e9a into main May 10, 2026
13 checks passed
@bokelley
bokelley deleted the bokelley/4321-prospect-on-conflict branch May 10, 2026 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant