Repository navigation
fix(server): prospect domain conflict no longer transfers ownership (#4321) - #4323
Merged
Merged
Conversation
…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'; |
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 medium finding in #4321.
Before #4159 Stage 2,
organization_domains.is_primaryonly drove org-membership inference; after Stage 2 it also drives brand identity. TheON CONFLICT (domain) DO UPDATEincreateProspectwas rewritingworkos_organization_idandis_primary=trueon conflict — silently transferring brand identity from the original owner to a fresh prospect org.Switch to
ON CONFLICT (domain) DO NOTHINGand log when the existing row is owned by a differentworkos_organization_id.Two layers of defense
resolveOrgByDomain— already rejects callers whose domain is already linked. This is the path users hit in normal operation.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=trueinserts inadmin/domains.ts/organization-bootstrap.tsfrom non-WorkOS sources, and the FOR UPDATE serialization comment correction inme-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
tests/integration/prospect-domain-conflict.test.ts— 3 cases:prospect-triage-function,claim-prospect-org,find-claimable-prospect-org(20/20).🤖 Generated with Claude Code