System messages set via CodexHtmlForm::setSubmitTextMsg are inserted unescaped into raw HTML by CodexHtmlForm, allowing for stored XSS.
Reproduction steps
- Add the following to your LocalSettings.php:
$wgUseCodexSpecialBlock = true; $wgEnableMultiBlocks = true; $wgUseXssLanguage = true;
- Go to /wiki/Special:Block?uselang=x-xss
Cause
SpecialBlock uses HtmlForm::setSubmitTextMsg to set the submit button label to a message:
https://github.com/wikimedia/mediawiki/blob/9f7d6e01394306ac1c32b5602d2e545a7f50b320/includes/specials/SpecialBlock.php#L301-L302
HtmlForm::setSubmitTextMsg sets the submit text to the message in the text() output mode without escaping any characters:
https://github.com/wikimedia/mediawiki/blob/9f7d6e01394306ac1c32b5602d2e545a7f50b320/includes/htmlform/HTMLForm.php#L1557
CodexHtmlForm retrieves this value and assigns it to $submitButtonLabel:
https://github.com/wikimedia/mediawiki/blob/9f7d6e01394306ac1c32b5602d2e545a7f50b320/includes/htmlform/CodexHTMLForm.php#L172
The value is passed to HTMLButtonField::buildCodexComponent:
https://github.com/wikimedia/mediawiki/blob/9f7d6e01394306ac1c32b5602d2e545a7f50b320/includes/htmlform/CodexHTMLForm.php#L190-L194
HTMLButtonField inserts the label as raw HTML using Html::rawElement:
https://github.com/wikimedia/mediawiki/blob/9f7d6e01394306ac1c32b5602d2e545a7f50b320/includes/htmlform/fields/HTMLButtonField.php#L174-L176
I think this issue should be fixed in HTMLButtonField, as the documentation does not clearly state that the parameter is used as HTML:
* @param string $buttonLabel The button's label attribute.
