matomo-org / matomo-org/plugin-LoginLdap
synchronizeLdapUser() does not abort when an LDAP login collides with an existing non-LDAP user
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 37
- Forks
- 30
- Avg merge
- 22h 53m
- Merged PRs (30d)
- 19
Description
In `LdapInterop/UserSynchronizer.php`, `synchronizeLdapUser()` detects when an LDAP login matches an existing native (non-LDAP) Matomo user and logs a warning, but then falls through instead of aborting:
```php
} else {
if (!$userMapper->isUserLdapUser($existingUser['login'])) {
$logger->warning("Unable to synchronize LDAP user '{user}', non-LDAP user with same name exists.", ...);
} else {
$userUpdater->updateUserWithoutCurrentPassword(...);
}
}
$userMapper->markUserAsLdapUser($user['login']);
return $userModel->getUser($user['login']);
```
Because the warning branch does not return or throw, `markUserAsLdapUser()` runs unconditionally and the method returns the existing native user record. In default `LdapAuth` mode this means a directory entry whose `uid` equals an existing native account is authenticated as that native account, and the native account is silently converted to an LDAP user (its stored password hash is overwritten on a subsequent login).
Suggested fix: in the non-LDAP collision branch, abort synchronization (throw, or return a failure the caller treats as an auth failure) instead of falling through, and only call `markUserAsLdapUser()` after a successful synchronization.
Tested on LoginLdap 5.2.1 with Matomo 5.13. Filed as a regular hardening bug per a maintainer suggestion.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in LdapInterop/UserSynchronizer.php at synchronizeLdapUser() and trace how its result is handled by the authentication caller. Reproduce the collision between an LDAP login and an existing native account, then verify that synchronization aborts and markUserAsLdapUser() is not reached; add or run the relevant regression coverage if available.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- authentication, security
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100