Skip to content

fix: only accept and update WordPress passwords of linked accounts - #30

Merged
vitormattos merged 1 commit into
fix/add-command-to-link-wordpress-usersfrom
fix/require-wordpress-link
Nov 14, 2026
Merged

vitormattos merged 1 commit into
fix/add-command-to-link-wordpress-usersfrom
fix/require-wordpress-link

Conversation

@YvesCesar

Copy link
Copy Markdown
Member

What was wrong

  • The user backend accepted the WordPress password for any Nextcloud account whose uid had the same text as a WordPress user_login, including accounts that never came from WordPress (group members, admins, service accounts).
  • The password listener wrote every Nextcloud password change to the WordPress user with the same login, again without any link between the two accounts. It also ran on BeforePasswordUpdatedEvent, so a password later refused by Nextcloud was already written to WordPress.
  • The default queries matched user_login or user_email and compared with the database collation, so the same uid could resolve to a different WordPress user (another user's e-mail, or a login differing only in case), and the backend took the first row returned.

What changed

  • An account is accepted by the backend only when its user preference wordpress_login (app wordpress_login_backend) is exactly its uid and a WordPress user has exactly that user_login. The lookup filters the rows in PHP, so custom queries are covered too, and checkPassword returns the Nextcloud uid.
  • The listener now handles PasswordUpdatedEvent, returns early for accounts without the same link, and logs a failed WordPress update instead of throwing after Nextcloud already changed the password. It was renamed to PasswordUpdatedListener.
  • Default queries match only the exact login (HEX(user_login) = HEX(:username) keeps the comparison byte exact on case insensitive collations); get_disabled_users no longer searches e-mails.
  • The WordPress lookup and update live in Db\WordPressUsers, shared with the link command.
  • README: link requirement, deploy order and the minimum database grants for the DSN.

Dependencies and merge order

How it was verified

  • New unit tests for the backend: a linked account authenticates; an account without the link, or linked to another login, does not; with an e-mail shaped uid and two WordPress users (one with that login, another with that e-mail), only the password of the user with that login is accepted; a WordPress login differing only in case is refused.
  • Listener tests: write-back happens only for linked accounts; a login differing only in case keeps its hash; a failed update is logged without throwing.
  • The SQLite test tables use a case insensitive collation for user_login, like MySQL; the tests fail on main.
  • composer run lint and composer run test:unit pass locally.
  • On a local Nextcloud with test accounts: without the link the WordPress password was refused; after linking the owner, it logged in and the group member still did not; a password change wrote to WordPress only for the linked owner.

Signed-off-by: YvesCesar <yvesamorim73@gmail.com>
@vitormattos
vitormattos merged commit 87bcc18 into fix/add-command-to-link-wordpress-users Nov 14, 2026
7 checks passed
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.

2 participants