Page MenuHomePhabricator

OAuth extension's Utils::getCentralDB() is used both for OAuth DB handle and central wiki DB handle
Closed, ResolvedPublicBUG REPORT

Description

Since T348485: Migrate OAuth to use a virtual database domain, the OAuth virtual DB domain and central wiki are separate settings, but Utils::getCentralDB() is used for getting both, breaking the wiki if the DB domain doesn't happen to be the central wiki's local DB. At a minimum, the logic for creating logging table entries needs to be updated.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Change #1201716 had a related patch set uploaded (by D3r1ck01; author: Derick Alangi):

[mediawiki/extensions/OAuth@master] Remove migration code when migrating to virtual domain

https://gerrit.wikimedia.org/r/1201716

Ah, apologies about that @Tgr, I was supposed to remove that migration code after the migration. Made a fix, thanks for filing the issue.

DAlangi_WMF changed the task status from Open to In Progress.Nov 4 2025, 4:17 PM
DAlangi_WMF claimed this task.

The migration code is fine. We are simply using Utils::getCentralDB() for two different things which happened to be identical as long as the OAuth DB was always the same as the central wiki DB, but now they aren't. We now either need to split that method into something like getOAuthDB() and getCentralWikiDB() or always use the local wiki DB for logs etc (that's less nice, but it should work in practice since all the management interfaces are disabled outside the central wiki). Needs an audit of where the central DB is used.

Change #1201716 merged by jenkins-bot:

[mediawiki/extensions/OAuth@master] Emit deprecation warnings when virtual domain isn't set

https://gerrit.wikimedia.org/r/1201716

What's needed here is creating a Utils::getCentralWikiDB() method, and reviewing the callers of Utils::getCentralDB(), some of which need the central wiki DB instead (the Special:Log handling, at least).

Change #1213454 had a related patch set uploaded (by D3r1ck01; author: Derick Alangi):

[mediawiki/extensions/OAuth@master] Appropriately use virtual doamin and central wiki DB in OAuth

https://gerrit.wikimedia.org/r/1213454

Change #1213454 merged by jenkins-bot:

[mediawiki/extensions/OAuth@master] Appropriately use virtual domain and central wiki DB in OAuth

https://gerrit.wikimedia.org/r/1213454

What's needed here is creating a Utils::getCentralWikiDB() method, and reviewing the callers of Utils::getCentralDB(), some of which need the central wiki DB instead (the Special:Log handling, at least).

I double-checked the changes in Derick's patch, and I think all remaining uses of getCentralDB (renamed to getOAuthDB) are correct.

I also tested this by moving my existing OAuth extension tables to a new database separate from the wiki database, as follows:

create database oauth;

create table oauth.oauth_registered_consumer like mediawiki.oauth_registered_consumer;
insert into oauth.oauth_registered_consumer select * from mediawiki.oauth_registered_consumer;
drop table mediawiki.oauth_registered_consumer;

create table oauth.oauth_accepted_consumer like mediawiki.oauth_accepted_consumer;
insert into oauth.oauth_accepted_consumer select * from mediawiki.oauth_accepted_consumer;
drop table mediawiki.oauth_accepted_consumer;

create table oauth.oauth2_access_tokens like mediawiki.oauth2_access_tokens;
insert into oauth.oauth2_access_tokens select * from mediawiki.oauth2_access_tokens;
drop table mediawiki.oauth2_access_tokens;
LocalSettings.php
$wgMWOAuthCentralWiki = 'mediawiki';
$wgVirtualDomainsMapping['virtual-oauth'] = [ 'db' => 'oauth' ];

Then going through various workflows (consumer registration, browsing lists, authorizing and making edits via OAuth). Everything worked correctly (whereas before the patch, consumer registration would throw InvalidArgumentException: DB connection domain 'oauth' does not match 'mediawiki' from ActorStore->checkDatabaseDomain()).