Page MenuHomePhabricator

Port wikibase templates to Mustache
Open, MediumPublic

Description

Context

Wikibase currently uses a homegrown templating system to assemble the user interface HTML both in PHP and in JS. In this templating system (view/src/Template/ + view/resources/wikibase/templates.js), the caller is responsible for escaping any template arguments; forgetting to escape an argument can result in a security vulnerability (e.g. T339111: CVE-2023-37302: Style injection into badges on Wikidata due to unescaped quotes. Escape messages in TermsListView).

At some later time, MediaWiki core gained support for mustache-based templates, also both in PHP and JS. This system escapes template arguments by default; parameters that should not be escaped are marked in the template and can easily be searched for and audited (git grep -F '{{{' '*.mustache'). Template arguments are also passed by name in this system ({{title}}) rather than by number as in Wikibase’s system ($2).

Main Objectives

The objective of this task is to migrate all uses of the old templating system in Wikibase to the new system, and eventually remove the old system from Wikibase altogether. This will make the code more readable, more similar to other MediaWiki extensions, and help to prevent future security vulnerabilities. It will also probably reduce the coupling within Wikibase (since the bindings to Wikibase’s template system will be gone).

Considerations

Since we use the same templates in PHP and JS, and the template syntax will change, care must be taken to migrate PHP and JS at the same time. That said, it might be possible to split the migration by template (i.e., do the PHP+JS migration of wikibase-statementgrouplistview first, then the PHP+JS migration of wikibase-entitytermsview, etc.).

Details

Event Timeline

daniel raised the priority of this task from to Needs Triage.
daniel updated the task description. (Show Details)
daniel added a project: Wikidata.
daniel subscribed.
Lydia_Pintscher set Security to None.

Wikibase’s homegrown template system has recently caused several security vulnerabilities (primarily T339111: CVE-2023-37302: Style injection into badges on Wikidata due to unescaped quotes; Escape messages in TermsListView was just merged on master since it was found before the vulnerable code was deployed anywhere). I suggest we prioritize this migration.

Change 935001 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@master] Decouple Template from Message

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

(The above change doesn’t implement this task yet, it just simplifies the existing code in preparation.)

The current Wikibase code also has a regex in JS which eslint now detects as being unsafe (see discussion). We’re not 100% sure if it’s actually exploitable in practice or not, but migrating to mustache would also resolve that issue.

Change 935001 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Decouple Template from Message

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