Page MenuHomePhabricator

Rename help key to help-raw in HTMLForm and deprecate old key name
Open, LowPublicSecurity

Description

The HTMLForm library doesn't escape the input of the help key by default. Is this intended behavior?

For example, the following form descriptor using an interface message through wfMessage()->text() is an XSS vector.

$formDescriptor= [
  'simpletextfield' => [
     'label' => 'Simple Text Field',
     'class' => 'HTMLTextField',
     'help' => wfMessage( 'myextension-mymessage' )->text(), // not escaped by HTMLForm, XSS!
   ]
]

We should rename the key to be help-raw, so users know it is a raw key. We should mark the old key name deprecated but keep it around for a transition period.

Afterwards we should adjust phan-taint-check to make sure it recognizes the new key name.

If you are fixing this, you probably need to edit (the comment in) includes/htmlform/HTMLForm.php and includes/htmlform/HTMLFormField.php as well as mentioning the deprecation in RELEASE-NOTES

Details

Risk Rating
Low
Author Affiliation
Wikimedia Communities

Event Timeline

I believe this is intentional, as some help messages can contain small amounts of harmless html for formatting purposes. This is a pattern we'd likely try to correct though, if found in actual code. And we do that in various ways (see also T347742 et al). Otherwise it's generally incumbent upon an engineer or developer to have a good understanding the MediaWiki Messages API and its output modes.

I believe this is intentional, as some help messages can contain small amounts of harmless html for formatting purposes. This is a pattern we'd likely try to correct though, if found in actual code. And we do that in various ways (see also T347742 et al). Otherwise it's generally incumbent upon an engineer or developer to have a good understanding the MediaWiki Messages API and its output modes.

Is there a reason we can't make it use something like 'raw' to make it possible to not escape, I was wondering?

Is there a reason we can't make it use something like 'raw' to make it possible to not escape, I was wondering?

There isn't any technical reason, no. But it might break a bunch of existing help messages and irritate other developers who want this kind of flexibility. If we were going to go this route, we should just make this bug public and put up a gerrit change set for feedback and review.

I've always hated that the key is named help instead of help-raw or help-html. Its super confusing. I'd support making a new name for the key and deprecating the old name.

I've always hated that the key is named help instead of help-raw or help-html. Its super confusing. I'd support making a new name for the key and deprecating the old name.

+1. If nothing it would at least make it consistent with the naming scheme used in for example label/label-raw.

I've always hated that the key is named help instead of help-raw or help-html. Its super confusing. I'd support making a new name for the key and deprecating the old name.

+1. If nothing it would at least make it consistent with the naming scheme used in for example label/label-raw.

patch-welcome. If someone is willing to get started on that, we can definitely make this task public.

I'll give it a try. I need some experience with gerrit, and this looks like a good chance.

sbassett changed Author Affiliation from N/A to Wikimedia Communities.
sbassett edited projects, added SecTeam-Processed; removed Security-Team.
sbassett changed the visibility from "Custom Policy" to "Public (No Login Required)".
sbassett changed the edit policy from "Custom Policy" to "All Users".
sbassett changed Risk Rating from N/A to Low.

Sorry, won't be able to work on this after all.

Sorry, won't be able to work on this after all.

No worries. Patches are always welcome but never an obligation. Raising the issue is in and of itself a contribution to MediaWiki :)

Bawolff renamed this task from HTMLForm doesn't escape the help key by default to Rename help key to help-raw in HTMLForm and deprecate old key name.Feb 17 2024, 9:07 PM
Bawolff added a project: good first task.
Bawolff updated the task description. (Show Details)