Page MenuHomePhabricator

CVE-2025-61642: Stored XSS through system messages provided to CodexHtmlForms
Closed, ResolvedPublicSecurity

Description

System messages set via CodexHtmlForm::setSubmitTextMsg are inserted unescaped into raw HTML by CodexHtmlForm, allowing for stored XSS.

Reproduction steps

  1. Add the following to your LocalSettings.php:
$wgUseCodexSpecialBlock = true;
$wgEnableMultiBlocks = true;
$wgUseXssLanguage = true;
  1. Go to /wiki/Special:Block?uselang=x-xss

image.png (376×563 px, 12 KB)

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.

https://github.com/wikimedia/mediawiki/blob/9f7d6e01394306ac1c32b5602d2e545a7f50b320/includes/htmlform/fields/HTMLButtonField.php#L144-L156

Additional information

Event Timeline

Hmmm I wonder why taint-check didn't catch these, even with --analyze-twice; maybe it's T289314 (happy 4th birthday to that task!).

I think this issue should be fixed in HTMLButtonField, as the documentation does not clearly state that the parameter is used as HTML:

Yeah, I think we should htmlspecialchars $submitButtonLabel. The call in HTMLButtonField#137 does that already for the default, and it otherwise passes $this->buttonLabel which is also already escaped.

Hmmm I wonder why taint-check didn't catch these, even with --analyze-twice; maybe it's T289314 (happy 4th birthday to that task!).

From a quick look, I think it can determine that something unsafe ends up being passed in that rawElement call. However, what I didn't remember well, is that this alone won't emit an issue. rawElement is not annotated with EXEC taint, so we'd only emit an issue when the element is output. For the code in question, HTMLForm::getHTML calls $this->getButtons() which includes the tainted element, but because of T289314, we do not check the subclass implementation of getButtons. If we did that, we might be able to catch these given the addHTML call in displayForm, modulo potentially increasing the analysis max recursion depth, and assuming it isn't also affected by T274780.

+2

Deployed

Reedy renamed this task from Stored XSS through system messages provided to CodexHtmlForms to CVE-2025-61642: Stored XSS through system messages provided to CodexHtmlForms.Sep 29 2025, 1:26 PM

Change #1193175 had a related patch set uploaded (by Reedy; author: Catrope):

[mediawiki/core@REL1_43] SECURITY: Escape submit button label for Codex-based HTMLForms

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

Change #1193200 had a related patch set uploaded (by Reedy; author: Catrope):

[mediawiki/core@REL1_44] SECURITY: Escape submit button label for Codex-based HTMLForms

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

Change #1193175 merged by jenkins-bot:

[mediawiki/core@REL1_43] SECURITY: Escape submit button label for Codex-based HTMLForms

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

Change #1193200 merged by jenkins-bot:

[mediawiki/core@REL1_44] SECURITY: Escape submit button label for Codex-based HTMLForms

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

Change #1193222 had a related patch set uploaded (by Reedy; author: Catrope):

[mediawiki/core@master] SECURITY: Escape submit button label for Codex-based HTMLForms

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

Change #1193222 merged by jenkins-bot:

[mediawiki/core@master] SECURITY: Escape submit button label for Codex-based HTMLForms

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

sbassett triaged this task as Medium priority.Mon, Apr 6, 9:08 PM
sbassett removed a project: Patch-For-Review.
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 Medium.
sbassett moved this task from Watching to Our Part Is Done on the Security-Team board.