Page MenuHomePhabricator

CommunityConfiguration Callers of Loader::load() should not be able to affect the internal cache of the Loader class
Closed, ResolvedPublic

Description

Problem statement

Loader is a MediaWiki-extensions-CommunityConfiguration class that is responsible for loading the content of an on-wiki JSON page, wrapped in a StatusValue. The caller will do Loader::load( $title ), which would give them a StatusValue with either an error or the content of the JSON page represented as an stdClass. Unfortunately, stdClass in PHP is passed by reference, and is not copied around when passed function to function. This means it is possible for Loader callers to corrupt Loader's own internal cache. An example is the following:

> $loader = \MediaWiki\MediaWikiServices::getInstance()->get('CommunityConfiguration.WikiPageStore.Loader')
= MediaWiki\Extension\CommunityConfiguration\Store\WikiPage\Loader {#5791}

> $data = $loader->load(Title::newFromText('MediaWiki:GrowthExperimentsHelpPanel.json'))->getValue()
= {#5862
    +"GEHelpPanelLinks": [],
    +"GEHelpPanelReadingModeNamespaces": [
      12,
    ],
    +"GEHelpPanelSearchNamespaces": [
      5,
    ],
    +"GEHelpPanelExcludedNamespaces": [
      2,
    ],
    +"GEHelpPanelHelpDeskTitle": "Alejandría",
  }

> unset( $data->GEHelpPanelExcludedNamespaces )
> 
> 
> $loader->load(Title::newFromText('MediaWiki:GrowthExperimentsHelpPanel.json'))->getValue()
= {#5862
    +"GEHelpPanelLinks": [],
    +"GEHelpPanelReadingModeNamespaces": [
      12,
    ],
    +"GEHelpPanelSearchNamespaces": [
      5,
    ],
    +"GEHelpPanelHelpDeskTitle": "Alejandría",
  }

>

If one of the many callers unsets a property (or changes a property) on the stdClass, this change will propagate back to Loader's in-process cache, being returned to the next caller.

Solution

After discussing this problem with @Catrope at the 2024 Hackathon, we should make Loader::load() return a copy of the data (at the very least, of the stdClass). That way, manipulating it in the caller should not affect any other caller.

Event Timeline

Change #1026862 had a related patch set uploaded (by Urbanecm; author: Urbanecm):

[mediawiki/extensions/CommunityConfiguration@master] Do not let callers to modify Loader::load's internal cache

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

Change #1026862 merged by jenkins-bot:

[mediawiki/extensions/CommunityConfiguration@master] Do not let callers to modify Loader::load's internal cache

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