Repository navigation
dev/core#6931 - Fix orphan contact on login for a second account with the same email - #38237
ayush-compuco wants to merge 2 commits into
Conversation
|
🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷 Introduction for new contributors...
PR commands & links...
|
|
The issue associated with the Pull Request can be viewed at https://lab.civicrm.org/dev/core/-/issues/6931 |
civireview
left a comment
There was a problem hiding this comment.
CiviReview: 🟢 Ready · Confidence: 4/5 ★★★★☆
Summary: Stops synchronizeUFMatch() from creating an orphan contact when another CMS account already holds the same email as uf_name. The session uses the other account's contact, and the conflict is now logged. A/B testing proved 2 test(s) failed on base, passed on PR.
Merge Confidence (4/5): CI / Jenkins failed (likely unrelated flake).
- PR:
civicrm/civicrm-core#38237· Kind:core-bugfix· Commits:96f3b25→28c3991
Findings
No verified high-signal issues found above the confidence gate.
Empirical Verification Matrix
| Check | Status | Detail |
|---|---|---|
| CI / Jenkins | 1 CI checks: 0 passed, 1 failed, 0 pending (3 failed test(s) extracted). — failed tests: CiviDrupal\PhpVersionTest::testConstantMatch, CiviDrupal\PhpVersionTest::testInfoMatch, CiviWP\PhpVersionTest::testConstantMatch — likely unrelated flake: Failures are CiviDrupal/CiviWP PhpVersionTest constant/info version mismatches ('8.1.2'). They are unrelated to UFMatch, and the PR's own tests pass. | |
| A/B Proof-of-Fix | ✅ PASS | 2 test(s) failed on base, passed on PR (+3 regression-guard test(s) passed on both base & PR: testSynchronizeUFMatchDoesNotHandOverContactOfStaleUFName, testSynchronizeUFMatchLinksUnlinkedContactWithSameEmail, testSynchronizeUFMatchCreatesLinkedContactForNewEmail) |
| Base-Test Regression | ✅ PASS | ck ab (junit) exited with 0 |
| Live Surface Diff | ✅ PASS | Live APIv4/APIv3/routes/Afform surface diff captured with 0 risk flags. |
Detailed Walkthrough (7 notes)
- PROVEN (A/B): the login and form-submission cases of testSynchronizeUFMatchDoesNotCreateContactWhenEmailIsTaken are red on base and green on the PR. No regressions were reported.
- CONFIRMED (diff): a new pre-check, getMatchOfAccountWithSameEmail(), runs before contact creation. It looks up uf_name in the domain and calls getUserObject() to check that the other account's current CMS email still matches. If it does, the session gets that account's contact_id and no uf_match row is saved. The existing $msg conflict is now logged.
- NEEDS_QUESTION (security): a session gets another account's contact when the emails match. getLoggedInContactID() then points at someone else's record, so ACLs and permissions apply to that contact. Is this safe where the CMS does not verify emails, and does it allow impersonation or data exposure?
- NEEDS_QUESTION: the early return skips the rest of synchronizeUFMatch() (session setup, the
$statusreturn path). Is it correct that the return value is$newContactwhen$statusis set? No row is saved, so every page view may repeat the lookup. - Three of the added tests passed on the unfixed base (stale uf_name, link existing contact, create new). They guard existing behaviour and do not prove the fix.
- NOT VERIFIED: real Drupal, Backdrop and WordPress behaviour. getUserObject() is only mocked in tests, and WordPress, Joomla and Standalone are unchanged by design. The stale-uf_name case still creates a new contact, as the author notes.
- CI: the failures are PhpVersionTest constant/info mismatches, which are unrelated to UFMatch.
CiviCRM Core Standards (4 checks — all PASS/N/A)
| Code | Status | Note |
|---|---|---|
r-explain |
PASS | The PR body and code comments explain the change. |
r-tech |
PASS | Backed by sec-1: in the conflict case synchronizeUFMatch returns another account's contact_id, and synchronize() puts it into the session as the logged-in contact. That changes access to own-contact data on CMS setups that allow shared emails. (Reconciled: no surviving verified findings.) |
r-maint |
PASS | Two data sets fail on the base and pass with the fix. Three added tests pass on the base too, so they are regression guards for normal matching and the stale uf_name case. |
r-test |
PASS | The CI failures (PhpVersionTest) are unrelated. The A/B run found no regressions. |
Reviewed by civireview · sonnet-opus · 197,683 tokens · $0.43
28c3991 to
bb0d87b
Compare
…same email Core PR: civicrm#38237
…same email Core PR: civicrm#38237
|
Updated the PR to address the CI / Jenkins check failing. |
|
I checked the logs of the civireview run above (the tool is still very alpha) and found an issue that got lost in the final verification stage. The review should not have said "Ready". This PR introduces a security problem. When a second CMS account logs in with an email that another account already holds, Default Drupal enforces unique emails, so this only triggers where duplicates are possible (e.g. sharedemail, SSO/social login, imports). That is exactly where the same email does not mean the same person. The existing conflict check deliberately refuses to link a contact that is already linked to another account (CRM-9091). On master this is not a security issue, it only leaves orphan contacts. A safer fix: create the contact once and save the |
bb0d87b to
b4e54c8
Compare
…same email Core PR: civicrm#38237
…same email Core PR: civicrm#38237
|
Thanks @jfilter, you're right: the session would carry the other contact's ACLs. I've switched to your suggestion. When another user already holds the email as |
|
@jfilter I've added a second commit. Our QA found that adding a user in Drupal failed with "DB Error: already exists" when another user held the email as |
…same email Core PR: civicrm#38237
Overview
Before
After
Technical Details
Comments