Repository navigation
fix(security): never link a profile to another organization's login account - #414
Merged
roncodes merged 2 commits intoOct 23, 2026
Merged
Conversation
…ccount Creating a driver, customer or contact looked up the login account by email or phone across the whole instance and linked any managed account of the same type to the new profile, adding it to the caller's organization. Any API key holder could reveal another tenant's driver (name, email, phone came back in the response) by guessing a phone number, attach that login to their own organization, and then change its email, phone or password through the profile update and credential endpoints. - ProfileAccountManager only reuses an account that already belongs to the requesting organization (or belongs to none). Another organization's account is refused with the generic "already in use by another account" error, which reveals neither its details nor its type. - Accounts already shared with another organization only take the name from profile updates, and driver/customer credential and login actions refuse them. - POST /v1/drivers no longer creates drivers in whatever company the `company` parameter names: anything but the credential's own organization is refused like an unknown company.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release/v0.6.75 #414 +/- ##
===================================================
Coverage 100.00% 100.00%
- Complexity 13596 13607 +11
===================================================
Files 634 634
Lines 49342 49352 +10
===================================================
+ Hits 49342 49352 +10
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
isUnowned() only looked at users.company_uuid and company_users, so an account with neither but a live driver or contact profile in another organization (a customer who signed up through a storefront, for example) could still be adopted by any organization that knew its email or phone. It now also requires that the account holds no profile anywhere.
Merged
Member
Author
|
Review: the rule (only reuse an account that already belongs to the organization) is right, and the refusals don't leak anything. I pushed one hardening fix (4161375):
Notes, not blocking:
Retargeted to |
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.
Security: profiles could take over another organization's login accounts
Impact
Fixes a cross-tenant identity bug in driver, customer and contact creation.
ProfileAccountManager::resolveForProfile()looked up the login account by email or phone across the whole instance. If it found a managed account (adriver,contactorcustomeruser) of the same type, it linked that account to the new profile and added it to the caller's organization, whichever organization the account belonged to. As a result, anyone holding an API key or a console session could:email,phoneandpasswordto the linked account (syncProxyFields). The console's reset-credentials, send-credentials and deactivate/reactivate actions also work on that account, for drivers and for customers. So the second organization could set a new password, or deactivate the login for the first.A separate problem was in the same endpoint:
POST /v1/driversaccepted acompanyparameter (a uuid or public id) and created the driver in that company, without checking that it belonged to the API credential.Reproduction (local stack, 2026-10-22)
+12065550201.POST /v1/drivers {"name":"Olive Odoo","email":"<unique>","phone":"+12065550201"}.Fix
Rule: an organization only reuses a login account that already belongs to it.
assertAccountCanHoldProfile()now requires company membership (users.company_uuidor acompany_usersrow) for every account, not only for staff accounts. A managed account that belongs to no organization at all (nocompany_uuidand no memberships) can still be adopted, because no tenant owns it.This email/phone number is already in use by another account.error (422). The error never includes the other account's name, email, uuid or organization. It also doesn't include its type: the oldalready used by a customermessage is now shown only for accounts in the caller's own organization.POST /v1/driversalways creates the driver in the credential's organization. Acompanyvalue that names any other organization, or none, gets the sameCompany not found.error as an unknown company, so the endpoint can't be used to check which companies exist.companyFromRequest()is removed.syncProxyFields()takes the profile's organization. For a shared account it only pushes the name, the same as for a staff account.This login is also used with another organization, so it can only be managed by its holder.Contact::createUserFromContact), and the profile-identity lookup hint, because they all go throughProfileAccountManager.Intentionally unchanged: public customer self-signup (
POST /v1/customersafterrequest-creation-code) can still attach to an existing account. That flow proves the person owns the identity by sending a verification code to it.Behaviour change: one person can no longer be added as a driver (or customer or contact) to a second organization just by entering their phone or email. That was the old intent: the test was named "a managed driver account of another organization is linked". Supporting it safely needs a flow where the account holder consents, such as an invite they accept. That would be a follow-up.
No core-api changes are needed.
Tests
ProfileAccountManagerTestisSharedWithAnotherCompanyandisUnowned.syncProxyFieldspushes only the name to a shared account.DriverControllerExistingUserAdoptionTest(internal create): new datasets for another organization's driver by email, by phone, and a customer. They assert the 422 body doesn't echo the existing account, and that nocompany_usersrow is created. The "another organization is linked" test is replaced by "a managed driver account of the organization is linked".ApiDriverControllerContractsTest: the own organization is accepted by uuid and by public id. Another organization, an empty value and a null value are refused before anything is resolved or created.DriverControllerLoginManagementTestandCustomerControllerCredentialsTest: every credential/login action refuses a shared login, and the password, status and mail are left untouched.Every changed statement in
server/srcis covered (per-file clover check).I ran the full suite one file at a time (507 files) against the branch. Three fixtures needed updating because the shared-account check queries
company_users/drivers, or becausecompanyFromRequestwas removed:ModelAccessorContractsTest,SmallModelSurfacesTestandDriverControllerSessionHelpersTest. After that, every file passes.