Page MenuHomePhabricator

HotCat loads code that can be edited without editsitejs right
Open, MediumPublic

Description

HotCat stores part of its configuration on various MediaWiki pages which do not have a .js extension: MediaWiki:Gadget-HotCat.js/<languagecode> for localisations (such as MediaWiki:Gadget-HotCat.js/mwl; the page could be either on Commons or the local wiki) and MediaWiki:Gadget-HotCat.js/local_defaults on the wiki where it's used for configuration settings (such as MediaWiki:Gadget-HotCat.js/local_defaults). These pages are not recognizable to MediaWiki as Javascript; they should either be renamed to .js; protected from editing without the editsitejs right by some other means (e.g. GetUserRights hook); or (preferably) convert those pages to JSON and rename them to .json so that more people are able to edit it without being able to deploy sitewide JS. (That last one does not work for hook callbacks, but no WMF wiki actually seems to use them.)

HotCat is used on several non-WMF wikis, often by loading the main file from Commons, so care should be taken not to break those.

Event Timeline

Left a message about it on the Commons gadget talk page (message, permalink).

At a glance, wikis which have their own copy of HotCat instead of hotloading from Commons include azbwiki, cebwiki, fawiki, idwikimedia, labswiki, mkwiki, mkwiktionary, nowiktionary, pswiki, ruwiktionary, urwikiquote, fdcwiki.

Its a really common pattern to do <msg>/langcode. Its even supported by us if the msg is not content language msg (which would be insane for a js msg).

Given that, i think maybe we should have mw consider anything where the base page name ends in .js in NS_MEDIAWIKI to be a js msg

Enwiki’s version uses regex literals and even functions, which are not allowed in JSON (they could be evaluated strings, of course, but code evaluation should be avoided, otherwise JSON’s protection is lost), meaning the possibility to use JavaScript has to be kept. So the following order might be good (if a page higher on the list is present, the script should not go any further):

  1. MediaWiki:Gadget-HotCat.js/local_defaults.json evaluated as JSON
  2. MediaWiki:Gadget-HotCat.js/local_defaults.js evaluated as JavaScript
  3. MediaWiki:Gadget-HotCat.js/local_defaults evaluated as JavaScript, restricted (possibly based on MediaWiki version: enabled the current stable release as of the implementation of this change, disabled in any later wmf or stable version)

Small comment: this can be mitigated without changing HotCat’s code ASAP by changing content model of such pages in every project to JavaScript (as it should be made, since it vastly improves their editing).

chasemp triaged this task as Medium priority.Dec 9 2019, 4:49 PM
chasemp added a project: Security-Team.