Page MenuHomePhabricator

Global user IDs are not guaranteed to be stable
Open, LowestPublic

Description

What I'm reporting here seems incredibly suspicious, so I could be spectacularly wrong because I misunderstood something, in which case I apologize.

Global uers have a global ID assigned by CentralAuth, and this is stored in the globaluser.gu_id field, an autoincrement primary key. CentralAuth has an option to delete a global account from Special:CentralAuth [side note: I couldn't find a single line of documentation about this feature]. When that happens, the row is deleted entirely from the table:

$centralDB->delete( 'globaluser', [ 'gu_name' => $this->mName ], __METHOD__ );

But then this mean that if the autoincrement value is reset for whatever reason (and this is a concrete possibility for InnoDB tables until MySQL version 8, AFAICS; no idea about other DBMSs), the ID of a deleted user could be reassigned to another global user.

This starts becoming a problem when someone uses global IDs to univocally identify global user accounts, which is easily made possible by CentralIdLookup (docs). It means that effectively, a record somewhere in MediaWiki which was meant to belong to global user X could first become orphan, and then get reassigned to user Y. And as it stands, we're only relying on the DBMS being sufficiently clever to avoid that.

Instead, I'm wondering if the "delete global account" feature should be reimplemented as a soft deletion, with the globaluser table having an additional gu_deleted field (or similar).

Event Timeline

taavi triaged this task as Lowest priority.Sep 22 2022, 5:40 PM
taavi subscribed.

The "delete global account" feature was originally implemented for the purposes of the SUL migration and it hasn't really been used since. I don't think soft deletion is the way to go here.

The "delete global account" feature was originally implemented for the purposes of the SUL migration and it hasn't really been used since. I don't think soft deletion is the way to go here.

Yeah, I noticed that, but the fact that this feature still exists and is so easily accessible worries me a bit. If we don't think it's needed anymore, perhaps it could be removed/disabled? It would be possible to keep the i18n messages for back-compat with old log entries.

The Wikimedia Wikis are running MariaDB 10.4+, where this should no longer be a problem. And since we don't really support CentralAuth for third parties, I don't really think we need to do something here.

The proper solution (besides dropping the feature) would be to re-implement something like https://gerrit.wikimedia.org/r/c/mediawiki/core/+/453117 for the globaluser table.

The Wikimedia Wikis are running MariaDB 10.4+, where this should no longer be a problem. And since we don't really support CentralAuth for third parties, I don't really think we need to do something here.

I definitely agree with this, but that also explains well why I'm worried about this potential bug: the fact that we're only assuming it can't happen. We're assuming that the DBMS will be kind enough to not reuse deleted auto increment values. We're assuming that the feature is no longer necessary and no-one will use it, ever again. We're assuming that CentralAuth is only used at Wikimedia. And for as strong and true these assumptions might be [1], they're just that, assumptions.

So yes, this may not be an immediate problem or something that must be fixed ASAP, but I would really like to see it fixed at some point. Somewhat relatedly, the CentralAuth extension is quite old and, TTBOMK, it has a lot of tech debt. You two guys have done, and are doing, an amazing work at maintaining it and not making it suck, but there are so many things that could be improved that it would be simply too much to ask from just a couple of volunteers. I've gone through this myself with AbuseFilter which, despite being old and full of tech debt, is not quite as complex as CentralAuth. What I want to say here is that if we have a feature that is no longer needed and possibly hiding some bugs, I would really consider dropping it for the sake of maintainability.

[1] - On an unrelated note, I do hope that some day, the functionality provided by CentralAuth will be better integrated with core; as a result, this could mean third parties using it successfully.

This task should be obsoleted in favor of T368016: Prevent deletion of non-empty global accounts so non-empty global accounts can no longer be deleted at all.

Update: If you mean "autoincrement value is reset for whatever reason" is possible, then page_id amd rev_id are not guaranteed to be unique either.