In T340201: Use custom language code to find i18n XSS issues, the x-xss language code was added to MediaWiki.
While this catches a lot of i18n XSSs caused by PHP code, vulnerabilities in Vue and JS code are often not caught by this, because script tags are not executed by the browser if inserted in certain ways.
Using an image tag with the src attribute set to an empty string and the onerror attribute set to JS code, more XSSs can be found.
This is why I locally use code similar to this to add an x-img-xss language code (taken from the x-xss task and modified):
$wgHooks['MessagesPreLoad'][] = function( $title, &$message, $code ) { if ( $code !== 'x-img-xss' ) { return true; } $key = lcfirst( preg_replace( '|/x-img-xss$|', '', $title ) ); $rawMessages = \MediaWiki\MediaWikiServices::getInstance() ->getMainConfig() ->get( \MediaWiki\MainConfigNames::RawHtmlMessages ); if ( in_array( $key, $rawMessages, true ) ) { return true; } $xssViaInnerHtml = "<img src=\"\" onerror=\"alert('$key')\">"; $xssViaAttribute = '">' . $xssViaInnerHtml . '<x y="'; $message = $xssViaInnerHtml . $xssViaAttribute; return false; };
The following security tasks/advisories contain vulnerabilities that could have been found using this language code:
- T396685: CVE-2025-6596: Vector inserts portlet labels as HTML, allowing for stored XSS through system messages
- T396946: CVE-2025-53496: Stored XSS through a system message in MediaSearch
- T398636: CVE-2025-61657: Stored XSS through system messages in sticky header buttons in Vector
- T400500: CVE-2025-62695: Stored XSS through system messages in WikiLambda
- T400526: CVE-2025-62702: Stored XSS through system messages in PageTriage
- T400545: CVE-2025-62701: Stored XSS through system messages in Wikistories
- https://github.com/advisories/GHSA-jwr7-992g-68mh
- https://github.com/advisories/GHSA-86xf-2mgp-gv3g
- https://github.com/advisories/GHSA-4c2h-67qq-vm87
Therefore, it would be useful for the x-xss language code to use <img> elements instead, so developers are able to detect a wider range of vulnerabilities in their code.
Since there are likely many more of those vulnerabilities in production code, this task should stay private for now, similarly to T340201, but it would be good to have this feature built into MW core eventually.